2022-11-26 20:45:32 +00:00
|
|
|
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),
|
2023-01-15 19:42:39 +00:00
|
|
|
nil,
|
2022-11-26 20:45:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
defer hook.Flush()
|
|
|
|
|
|
|
|
return hook, nil
|
|
|
|
}
|