You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, i am using the log API and it is easy to use and the output is correct. But i would
appreciate a new feature.
I'd like to be able to filter log lines according to a log level.
eg :
const (
Debug = 1
Info = 2
Warning = 3
Error = 4
)
type Logger struct {
...
level int
}
By default, the level could be Info to stay compatible with old releases.
func (l *Logger) SetLevel(aLevel int) {
l.level = aLevel
}
change :
func (l *Logger) Printf(format string, v ...interface{}) {
l.Output(2, fmt.Sprintf(format, v...))
}
by ;
func (l *Logger) Printf(format string, v ...interface{}) {
if l.level < WARNING {
l.Output(2, fmt.Sprintf(format, v...))
}
}
and add Debug function :
func (l *Logger) Debugf(format string, v ...interface{}) {
if l.level < INFO {
l.Output(2, fmt.Sprintf(format, v...))
}
}
As it, i may set Debug level during devs and Warning or Info during normal runtime.
Thanks for all you have done for go. It is a great language.
The text was updated successfully, but these errors were encountered:
It's very easy to do this with your own simple package that defines a struct that embeds
a Logger into a struct with a level. Whether that needs to be done in the standard
library is arguable.
by milak.mlk:
The text was updated successfully, but these errors were encountered: