parent
5a8acec808
commit
0b93bef031
@ -0,0 +1,30 @@ |
||||
package log |
||||
|
||||
// Verbose is a verbose type that implements Logger Print.
|
||||
type Verbose struct { |
||||
log Logger |
||||
level Level |
||||
enabled bool |
||||
} |
||||
|
||||
// NewVerbose new a verbose with level.
|
||||
func NewVerbose(log Logger, level Level) Verbose { |
||||
return Verbose{log: log, level: level} |
||||
} |
||||
|
||||
// Enabled will return true if this log level is enabled, guarded by the value of v.
|
||||
func (v Verbose) Enabled(level Level) bool { |
||||
return v.level <= level |
||||
} |
||||
|
||||
// V reports whether verbosity at the call site is at least the requested level.
|
||||
func (v Verbose) V(level Level) Verbose { |
||||
return Verbose{log: v.log, enabled: v.Enabled(level)} |
||||
} |
||||
|
||||
// Print is equivalent to the Print function, guarded by the value of v.
|
||||
func (v Verbose) Print(a ...interface{}) { |
||||
if v.enabled { |
||||
v.log.Print(a...) |
||||
} |
||||
} |
@ -0,0 +1,11 @@ |
||||
package log |
||||
|
||||
import "testing" |
||||
|
||||
func TestVerbose(t *testing.T) { |
||||
v := NewVerbose(DefaultLogger, 20) |
||||
|
||||
v.V(10).Print("foo", "bar1") |
||||
v.V(20).Print("foo", "bar2") |
||||
v.V(30).Print("foo", "bar3") |
||||
} |
Loading…
Reference in new issue