Skip to content

Commit 9a73082

Browse files
RoboticPrismmeta-codesync[bot]
authored andcommitted
Bugfix: Logger config not being respected (#563)
Summary: Pull Request resolved: #563 We currently make two calls to initialize the logger in this order: - when the logger package is imported with a default configuration - when we have initialized the configuration with the config we just initialized However, currently we have wrapped the logger initialization in a do once. This led to us always setting up a logger with default configurations and ignoring the second call with the configs we actually want. I opted to remove the init function (which is called when the package is loaded) and instead have the call for the global logger create a new empty config logger if one does not exist yet. In this case, this means we'll always yield to a provided config, but also that tests can just request and receive a standard logger without needing to create one manually in every test. Reviewed By: ivnik Differential Revision: D84361195 fbshipit-source-id: 022e201d7a514895a4b94e15fa1334d8d6010aad
1 parent 3e07c38 commit 9a73082

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

pkg/logging/logger.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,17 @@ var (
4444
indentLevel int
4545
)
4646

47-
func init() {
48-
// default logger - will be used in tests
49-
err := InitLog(Config{})
50-
if err != nil {
51-
// this should never fail - if it does
52-
// something weird happened so we panic
53-
panic(err)
54-
}
55-
}
56-
5747
// L returns the global logger for ttpforge
5848
func L() *zap.SugaredLogger {
49+
// If the logger is not initialized at this point, initialize it with default settings. Usually this should only happen in tests.
50+
if logger == nil {
51+
err := InitLog(Config{})
52+
if err != nil {
53+
// this should never fail - if it does
54+
// something weird happened so we panic
55+
panic(err)
56+
}
57+
}
5958
return logger
6059
}
6160

0 commit comments

Comments
 (0)