Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log enhencement #4269

Closed
gopherbot opened this issue Oct 20, 2012 · 1 comment
Closed

log enhencement #4269

gopherbot opened this issue Oct 20, 2012 · 1 comment

Comments

@gopherbot
Copy link
Contributor

by milak.mlk:

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.
@robpike
Copy link
Contributor

robpike commented Oct 20, 2012

Comment 1:

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.

Labels changed: added packagechange, removed priority-triage, go1.1.

Status changed to WorkingAsIntended.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants