// NewGraylogHook creates a hook to be added to an instance of logger. func NewGraylogHook(addr string, extra map[string]interface{}) *GraylogHook { g, err := NewWriter(addr) if err != nil { logrus.WithField("err", err).Info("Can't create Gelf logger") } hook := &GraylogHook{ Extra: extra, gelfLogger: g, synchronous: true, } return hook }
// NewAsyncGraylogHook creates a hook to be added to an instance of logger. // The hook created will be asynchronous, and it's the responsibility of the user to call the Flush method // before exiting to empty the log queue. func NewAsyncGraylogHook(addr string, extra map[string]interface{}) *GraylogHook { g, err := NewWriter(addr) if err != nil { logrus.WithField("err", err).Info("Can't create Gelf logger") } hook := &GraylogHook{ Extra: extra, gelfLogger: g, buf: make(chan graylogEntry, BufSize), } go hook.fire() // Log in background return hook }