Skip to content

Commit

Permalink
Adapt groupable to logsink
Browse files Browse the repository at this point in the history
  • Loading branch information
pepov committed Jan 18, 2022
1 parent 7edb7e7 commit 8ecf704
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,17 @@ func (log *logger) Grouped(state bool) {
}

func EnableGroupSession(logger interface{}) func() {
if l, ok := logger.(interface{ Grouped(state bool) }); ok {
l.Grouped(true)
return func() { l.Grouped(false) }
var l interface{}

if lwrap, ok := logger.(interface{ GetSink() logr.LogSink }); ok {
l = lwrap.GetSink()
} else {
l = logger
}

if lgroupable, ok := l.(interface{ Grouped(state bool) }); ok {
lgroupable.Grouped(true)
return func() { lgroupable.Grouped(false) }
}
return func() {}
}

0 comments on commit 8ecf704

Please sign in to comment.