2.2 KiB
2.2 KiB
Go GELF Logging Library
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 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 (
logpackage). - If GELF is not configured, logging still works locally via the standard logger.
Installation
go get scm.yoorie.de/go-lib/gelf
Quick Start
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
FatalandFatalfterminate the program by callinglog.Fatalf.- Graylog delivery uses UDP (
udp://host:port). - Calling
SetDefaultConfigagain replaces the previous client.
Development
Run tests:
go test ./...
Module information is defined in go.mod.
Additional Documentation
License
See LICENSE.
Copyright © 2023 yoorie.de