Skip to content

Commit

Permalink
config inspection (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
elijaharita authored Jan 9, 2022
1 parent 358e037 commit 370cc50
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"go.uber.org/zap/zapcore"
)

var config Config

func init() {
SetupLogging(configFromEnv())
}
Expand Down Expand Up @@ -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
Expand All @@ -100,6 +108,8 @@ func SetupLogging(cfg Config) {
loggerMutex.Lock()
defer loggerMutex.Unlock()

config = cfg

primaryFormat = cfg.Format
defaultLevel = cfg.Level

Expand Down

0 comments on commit 370cc50

Please sign in to comment.