Fluentd Hook for Logrus
Usage
import (
"github.com/sirupsen/logrus"
"github.com/evalphobia/logrus_fluent"
)
func main() {
hook, err := logrus_fluent.NewWithConfig(logrus_fluent.Config{
Host: "localhost",
Port: 24224,
})
if err != nil {
panic(err)
}
hook.SetLevels([]logrus.Level{
logrus.PanicLevel,
logrus.ErrorLevel,
})
hook.SetTag("original.tag")
hook.AddIgnore("context")
hook.AddFilter("error", logrus_fluent.FilterError)
logrus.AddHook(hook)
}
func logging(ctx context.Context) {
logrus.WithFields(logrus.Fields{
"value": "some content...",
"error": errors.New("unknown error"),
"context": ctx,
}).Error("error message")
}
Special fields
Some logrus fields have a special meaning in this hook.
tag
is used as a fluentd tag. (if tag
is omitted, Entry.Message is used as a fluentd tag, unless a static tag is set for the hook with hook.SetTag
)