Closed rafaeljusto closed 6 years ago
Hi, you can just set a new Level for the hook:
hook := NewGraylogHook("<graylog_ip>:<graylog_port>", map[string]interface{}{})
hook.Level = logrus.ErrorLevel
and the hook won't log anything below Error
. That's why this field is public actually.
Does that make sense to you?
Hi @gravis , the problem is that I would like to trigger the hook for everything that is bellow a specific log level (higher number in the logrus.Level
enum). So if I set WarnLevel
, I would like to trigger the graylog hook when the levels are WarnLevel
, InfoLevel
and DebugLevel
.
Still not sure I understand :)
When you set hook.Level
to WarnLevel
, it will already log everything for WarnLevel
and bellow, that's exactly how loggers work in logrus. So it will catch everything below that level, with https://github.com/gemnasium/logrus-graylog-hook/blob/master/graylog_hook.go#L231
If you want a specific behaviour, like logging for just WarnLevel
and ErrorLevel
for example, you can create your own hook by wrapping the existing one and replace the Levels
func.
What do you think?
When you set hook.Level to WarnLevel, it will already log everything for WarnLevel and bellow, that's exactly how loggers work in logrus. So it will catch everything below that level, with https://github.com/gemnasium/logrus-graylog-hook/blob/master/graylog_hook.go#L231
When you say WarnLevel and bellow
, you mean:
// A constant exposing all logging levels
var AllLevels = []Level{
PanicLevel, <-- this one
FatalLevel, <-- this one
ErrorLevel, <-- this one
WarnLevel, <-- this one
InfoLevel,
DebugLevel,
}
when actually I would like:
// A constant exposing all logging levels
var AllLevels = []Level{
PanicLevel,
FatalLevel,
ErrorLevel,
WarnLevel, <-- this one
InfoLevel, <-- this one
DebugLevel, <-- this one
}
And for this behaviour, the condition:
if level <= hook.Level {
levels = append(levels, level)
}
needs to be:
if level >= hook.Level {
levels = append(levels, level)
}
If you want a specific behaviour, like logging for just WarnLevel and ErrorLevel for example, you can create your own hook by wrapping the existing one and replace the Levels func. What do you think?
Yeah, I think wrapping will solve my problem! Thanks! 😄
That makes sense, sorry I wasn't getting your point :) Glad you can use wrapping!
Hey guys! When defining a level in
GraylogHook.Level
attribute it will be included also all lower levels. So if I defineDebugLevel
, it will also includeInfoLevel
,WarnLevel
,ErrorLevel
,FatalLevel
andPanicLevel
. But what if I just want to fire the hook when it'sDebugLevel
,InfoLevel
orWarnLevel
?I think we would need more flexibility from the logic defined here.