Zap GELF added availability to zap logger send your logs to Graylog server over UDP. All zap fields will be sent as additional fields on Graylog.
go get -u github.com/snovichkov/zap-gelf
- Use fast zap JSON serializer
- Support chunking over UPD
- Support gzip/zlib compression
package main
import (
"os"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"github.com/snovichkov/zap-gelf"
)
func main() {
var (
err error
host string
core zapcore.Core
)
if host, err = os.Hostname(); err != nil {
panic(err)
}
if core, err = gelf.NewCore(
gelf.Addr("127.0.0.1:12001"),
gelf.Host(host),
); err != nil {
panic(err)
}
var logger = zap.New(
core,
zap.AddCaller(),
zap.AddStacktrace(zap.LevelEnablerFunc(func(l zapcore.Level) bool {
return core.Enabled(l)
})),
)
defer logger.Sync()
logger.
With(
zap.String("with", "field"),
).
Error(
"An error was accrued",
zap.String("an_filed", "Hello word!"),
zap.String("id", "an_id"),
)
logger.
Sugar().
With(
"an_filed", "Hello word!",
"id", "an_id",
).
Error("An error was accrued")
}