Skip to content

Commit

Permalink
Read the value of logger output path from environment variable if set (
Browse files Browse the repository at this point in the history
…#293)

* Read the value of logger output path from environment variable if set

* Added lowercase check for logstream value
  • Loading branch information
abhide-tibco authored Oct 24, 2024
1 parent 7823f25 commit 2ce7fe8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions support/log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const (

EnvKeyLogSeparator = "FLOGO_LOG_SEPARATOR"
DefaultLogSeparator = "\t"
EnvLogConsoleStream = "FLOGO_LOG_CONSOLE_STREAM"
)

type Level int
Expand Down
13 changes: 11 additions & 2 deletions support/log/zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"os"
"strings"
)

var traceLogger *zap.SugaredLogger
Expand Down Expand Up @@ -158,8 +160,15 @@ func newZapLogger(logFormat Format, level Level) (*zap.Logger, *zap.AtomicLevel,
cfg := zap.NewProductionConfig()
cfg.DisableCaller = true

cfg.OutputPaths = []string{"stdout"}

// change the default output paths for the logger if the env variable is set and has the supported values (stderr and stdout).
// Otherwise, the logger will use the default value of stderr.
logstream, ok := os.LookupEnv(EnvLogConsoleStream)
if ok {
if strings.ToLower(logstream) == "stdout" || strings.ToLower(logstream) == "stderr" {
cfg.OutputPaths = []string{strings.ToLower(logstream)}
}
}

eCfg := cfg.EncoderConfig
eCfg.TimeKey = "timestamp"
eCfg.EncodeTime = zapcore.ISO8601TimeEncoder
Expand Down

0 comments on commit 2ce7fe8

Please sign in to comment.