logrus hooks up with the syslog on demand

If you’re trying to delegate what message to send by its log level then you can do it by setting the log levels the hook accepts.

For example:

    Writer: os.Stderr,
    LogLevels: []log.Level{ log.WarnLevel },
log.AddHook(lSyslog.NewSyslogHook("udp", "localhost:514", syslog.LOG_INFO, ""))
log.Info("This will go to syslog")
log.Warn("This will go to stderr")

If you want to route this no according to the log level then what you suggested may work but it feels odd and may have race-conditions.

What I suggest you to do is create your own hook that gets hook list and route to the right hook(s) according to the message or to the fields that are passed when calling Info, Warn and etc.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top