Skip to content

Commit 3a9983a

Browse files
authored
Merge pull request #121 from Icinga/logging-forcelog
logging: ForceLog option to log all messages
2 parents c2f0318 + 31eff16 commit 3a9983a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

logging/logging.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,14 @@ func (l *Logging) GetChildLogger(name string) *Logger {
117117
func (l *Logging) GetLogger() *Logger {
118118
return l.logger
119119
}
120+
121+
// ForceLog results in every message being logged.
122+
//
123+
// This [zap.Option] is the opposite of [zap.IncreaseLevel], it just decreases the log level to debug. Since zap's
124+
// architecture does not allow this with the same [zapcore.Core], it replaces the core with a freshly created one from
125+
// the Logging's core factory.
126+
func (l *Logging) ForceLog() zap.Option {
127+
return zap.WrapCore(func(_ zapcore.Core) zapcore.Core {
128+
return l.coreFactory(zap.NewAtomicLevelAt(zapcore.DebugLevel))
129+
})
130+
}

0 commit comments

Comments
 (0)