diff --git a/pkg/logger/logger.go b/pkg/logger/logger.go index 5ee2779..efd23bb 100644 --- a/pkg/logger/logger.go +++ b/pkg/logger/logger.go @@ -1,11 +1,20 @@ package logger import ( + "os" + "go.uber.org/zap" "go.uber.org/zap/zapcore" "gopkg.in/natefinch/lumberjack.v2" ) +func GetEnv(key, fallback string) string { + if value, ok := os.LookupEnv(key); ok { + return value + } + return fallback +} + var log *zap.Logger func init() { @@ -19,7 +28,7 @@ func init() { config.EncoderConfig = encoderConfig w := zapcore.AddSync(&lumberjack.Logger{ - Filename: "./ngonx-log/ngonx.log", + Filename: GetEnv(os.Getenv("NGONX_LOGS"), "./ngonx-log/ngonx.log"), MaxSize: 500, // megabytes MaxBackups: 3, MaxAge: 28, // days