Skip to content

Commit

Permalink
Merge pull request #103 from hyperledger-labs/no-logrus-defaults
Browse files Browse the repository at this point in the history
Do not force logrus LogLevel on first log line
  • Loading branch information
jimthematrix authored Nov 7, 2024
2 parents 9271b8a + b322547 commit 9855999
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions go-sdk/internal/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ var (
initAtLeastOnce atomic.Bool
)

// Optional to call if you wish to use Zeto's configuration for logging.
// Otherwise standard logrus logging will be used as configured by your own environment
func InitConfig() {
initAtLeastOnce.Store(true) // must store before SetLevel

Expand All @@ -51,22 +53,12 @@ func InitConfig() {
logrus.SetFormatter(formatter)
}

func ensureInit() {
// Called at a couple of strategic points to check we get log initialize in things like unit tests
// However NOT guaranteed to be called because we can't afford to do atomic load on every log line
if !initAtLeastOnce.Load() {
InitConfig()
}
}

func logger() *logrus.Entry {
ensureInit()
return rootLogger
}

// WithLogField adds the specified field to the logger in the context
func WithLogField(key, value string) *logrus.Entry {
ensureInit()
if len(value) > 61 {
value = value[0:61] + "..."
}
Expand Down

0 comments on commit 9855999

Please sign in to comment.