# Go GELF Logging Library ![yoorie favicon](https://www.yoorie.de/img/favicon_32.png) [![Build Status][build-badge]][build-link] Minimal helper package to send application logs to Graylog via GELF while still writing to the standard Go logger. ## Overview This module wraps [gopkg.in/aphistic/golf.v0][golf] and exposes a small API for common log levels. Behavior summary: - If GELF is configured with `SetDefaultConfig`, messages are sent to Graylog over UDP. - Messages are also written to the standard Go logger (`log` package). - If GELF is not configured, logging still works locally via the standard logger. ## Installation ```bash go get scm.yoorie.de/go-lib/gelf ``` ## Quick Start ```go package main import ( "scm.yoorie.de/go-lib/gelf" ) func main() { gelf.SetDefaultConfig("graylog.example.local", 12201, map[string]interface{}{ "service": "billing-api", "env": "prod", }, ) gelf.Info("service started") gelf.Infof("listening on %s", ":8080") gelf.Alert("database latency is high") } ``` ## API ### Configuration - `SetDefaultConfig(host string, port int, attrs map[string]interface{})` Creates and configures the default GELF logger. Attributes in `attrs` are attached as default fields to all GELF messages. ### Logging Functions - `Debug(msg string)` - `Debugf(format string, va ...interface{})` - `Info(msg string)` - `Infof(format string, va ...interface{})` - `Alert(msg string)` - `Alertf(format string, va ...interface{})` - `Fatal(msg string)` - `Fatalf(format string, va ...interface{})` ## Notes - `Fatal` and `Fatalf` terminate the program by calling `log.Fatalf`. - Graylog delivery uses UDP (`udp://host:port`). - Calling `SetDefaultConfig` again replaces the previous client. ## Development Run tests: ```bash go test ./... ``` Module information is defined in [go.mod](go.mod). ## Additional Documentation - [Definition of Done](docs/DEFINITION_OF_DONE.md) - [Releasing](docs/RELEASING.md) ## License See [LICENSE](LICENSE). --- Copyright © 2023 yoorie.de [build-badge]: https://drone.yoorie.de/api/badges/go-lib/gelf/status.svg [build-link]: https://drone.yoorie.de/go-lib/gelf [golf]: https://gopkg.in/aphistic/golf.v0