From 370cc50d9b731a6928367893f73c45d0e61364b4 Mon Sep 17 00:00:00 2001 From: Elijah Date: Sat, 8 Jan 2022 19:53:50 -1000 Subject: [PATCH] config inspection (#129) --- setup.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/setup.go b/setup.go index ffd84fb..e0d321e 100644 --- a/setup.go +++ b/setup.go @@ -13,6 +13,8 @@ import ( "go.uber.org/zap/zapcore" ) +var config Config + func init() { SetupLogging(configFromEnv()) } @@ -92,6 +94,12 @@ var primaryCore zapcore.Core // loggerCore is the base for all loggers created by this package var loggerCore = &lockedMultiCore{} +// GetConfig returns a copy of the saved config. It can be inspected, modified, +// and re-applied using a subsequent call to SetupLogging(). +func GetConfig() Config { + return config +} + // SetupLogging will initialize the logger backend and set the flags. // TODO calling this in `init` pushes all configuration to env variables // - move it out of `init`? then we need to change all the code (js-ipfs, go-ipfs) to call this explicitly @@ -100,6 +108,8 @@ func SetupLogging(cfg Config) { loggerMutex.Lock() defer loggerMutex.Unlock() + config = cfg + primaryFormat = cfg.Format defaultLevel = cfg.Level