Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not force logrus LogLevel on first log line #103

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no longer used

)

// 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
Loading