Skip to content

Commit

Permalink
Merge pull request #34 from kenriortega/log-format-flow
Browse files Browse the repository at this point in the history
ref: add var env validations
  • Loading branch information
kenriortega authored Nov 11, 2021
2 parents 8777d04 + 465b417 commit 25350a7
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/logger/logger.go
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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
Expand Down

0 comments on commit 25350a7

Please sign in to comment.