Skip to content

Commit 2ce7fe8

Browse files
authored
Read the value of logger output path from environment variable if set (#293)
* Read the value of logger output path from environment variable if set * Added lowercase check for logstream value
1 parent 7823f25 commit 2ce7fe8

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

support/log/logger.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const (
3232

3333
EnvKeyLogSeparator = "FLOGO_LOG_SEPARATOR"
3434
DefaultLogSeparator = "\t"
35+
EnvLogConsoleStream = "FLOGO_LOG_CONSOLE_STREAM"
3536
)
3637

3738
type Level int

support/log/zap.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"fmt"
55
"go.uber.org/zap"
66
"go.uber.org/zap/zapcore"
7+
"os"
8+
"strings"
79
)
810

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

161-
cfg.OutputPaths = []string{"stdout"}
162-
163+
// change the default output paths for the logger if the env variable is set and has the supported values (stderr and stdout).
164+
// Otherwise, the logger will use the default value of stderr.
165+
logstream, ok := os.LookupEnv(EnvLogConsoleStream)
166+
if ok {
167+
if strings.ToLower(logstream) == "stdout" || strings.ToLower(logstream) == "stderr" {
168+
cfg.OutputPaths = []string{strings.ToLower(logstream)}
169+
}
170+
}
171+
163172
eCfg := cfg.EncoderConfig
164173
eCfg.TimeKey = "timestamp"
165174
eCfg.EncodeTime = zapcore.ISO8601TimeEncoder

0 commit comments

Comments
 (0)