Changing the logging paradigm to only require a single logger. All logging will be disabled by default. If debug is enabled, and a logger has not been set, the library will default to printing all logging (INFO and DEBUG) to the stdout.
This commit is contained in:
parent
256ec2ea47
commit
7662277025
6 changed files with 90 additions and 60 deletions
26
logger.go
26
logger.go
|
@ -27,3 +27,29 @@ func (NoopLogger) Printf(format string, a ...interface{}) {}
|
|||
func (NoopLogger) Print(a ...interface{}) {}
|
||||
|
||||
func (NoopLogger) Println(a ...interface{}) {}
|
||||
|
||||
type LevelLogger struct {
|
||||
Logger
|
||||
debug bool
|
||||
}
|
||||
|
||||
func (l LevelLogger) DebugPrintf(format string, a ...interface{}) {
|
||||
if l.debug {
|
||||
l.Print("[DEBUG] ")
|
||||
l.Printf(format, a)
|
||||
}
|
||||
}
|
||||
|
||||
func (l LevelLogger) DebugPrint(a ...interface{}) {
|
||||
if l.debug {
|
||||
l.Print("[DEBUG] ")
|
||||
l.Print(a)
|
||||
}
|
||||
}
|
||||
|
||||
func (l LevelLogger) DebugPrintln(a ...interface{}) {
|
||||
if l.debug {
|
||||
l.Print("[DEBUG] ")
|
||||
l.Println(a)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue