Skip to content

Commit 96bad1d

Browse files
iamcalledrobthockin
authored andcommitted
Adds option to use non-global verbosity per logger.
1 parent 1fa2ed3 commit 96bad1d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

stdr.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func NewWithOptions(std StdLogger, opts Options) logr.Logger {
6868
sl := &logger{
6969
Formatter: funcr.NewFormatter(fopts),
7070
std: std,
71+
verbosity: opts.Verbosity,
7172
}
7273

7374
// For skipping our own logger.Info/Error.
@@ -88,6 +89,11 @@ type Options struct {
8889
// Go's log package has options to log this natively, too.
8990
LogCaller MessageClass
9091

92+
// Verbosity tells the logger which V logs to write. Higher values enable more logs.
93+
// If nil, the global value set by SetVerbosity will be used. A pointer is used to provide
94+
// nil as the default value.
95+
Verbosity *int
96+
9197
// TODO: add an option to log the date/time
9298
}
9399

@@ -114,13 +120,17 @@ type StdLogger interface {
114120

115121
type logger struct {
116122
funcr.Formatter
117-
std StdLogger
123+
std StdLogger
124+
verbosity *int
118125
}
119126

120127
var _ logr.LogSink = &logger{}
121128
var _ logr.CallDepthLogSink = &logger{}
122129

123130
func (l logger) Enabled(level int) bool {
131+
if l.verbosity != nil {
132+
return *l.verbosity >= level
133+
}
124134
return globalVerbosity >= level
125135
}
126136

0 commit comments

Comments
 (0)