gocommon/log/hooks/gelf/hook.go
Matthieu 'JP' DERASSE 5591da9c47
Some checks failed
continuous-integration/drone/push Build is failing
feat(log): Working on log library
2022-11-28 22:06:42 +00:00

29 lines
461 B
Go

package gelf
import (
"fmt"
"github.com/juju/errors"
"github.com/sirupsen/logrus"
graylog "github.com/gemnasium/logrus-graylog-hook/v3"
)
// NewHook will create a Gelf Hook for logrus.
func NewHook(c *ConfigStruct) (logrus.Hook, error) {
err := c.IsValid()
if err != nil {
return nil, errors.Trace(err)
}
hook := graylog.NewAsyncGraylogHook(
fmt.Sprintf("%s:%d", c.Host, c.Port),
c.ExtrasFields,
)
defer hook.Flush()
return hook, nil
}