Skip to content

Commit

Permalink
Remove configuration from context and into Init (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
bufnitza authored Sep 23, 2021
1 parent 25dc8f6 commit 08276ad
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func SetCorrelationIdContextKey(key string) {
correlationIdContextKey = key
}

func Init(ctx context.Context) {
func Init(ctx context.Context, enableLogLevelEndpoint, developmentMode bool) {
if logger != nil {
return
}
Expand All @@ -82,13 +82,12 @@ func Init(ctx context.Context) {
encoderConfig zapcore.EncoderConfig
atom zap.AtomicLevel
loggerMode []string
lsh bool
)

correlationIdContextKey = "correlation_id"
correlationIdFieldKey = "correlation_id"

if devEnv, ok := ctx.Value("env_development").(bool); ok && devEnv {
if developmentMode {
loggerMode = append(loggerMode, "dev")
atom = zap.NewAtomicLevelAt(zap.DebugLevel)
encoderConfig = zapcore.EncoderConfig{
Expand Down Expand Up @@ -148,7 +147,7 @@ func Init(ctx context.Context) {
}
}

if lsh, ok := ctx.Value("logger_serveHttp").(bool); ok && lsh {
if enableLogLevelEndpoint {
loggerMode = append(loggerMode, "serveHttp")
go func() {
mux := http.NewServeMux()
Expand All @@ -163,7 +162,7 @@ func Init(ctx context.Context) {
}

l.Info("Logger initialized successfully", zap.Strings("logger_modes", loggerMode))
if lsh {
if enableLogLevelEndpoint {
l.Info("Logger HTTP Server active on :53835/loglevel")
}

Expand Down

0 comments on commit 08276ad

Please sign in to comment.