Skip to content

Commit

Permalink
feat: enable to disable log color
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Feb 22, 2024
1 parent 13a660b commit 402668d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions log/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var GCPEnv = []string{
"CLOUD_RUN_JOB",
"K_SERVICE",
"GOOGLE_CLOUD_PROJECT",
"GCP",
}

type severity string
Expand Down
10 changes: 9 additions & 1 deletion log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ func encoder() zapcore.Encoder {
if isGCP() {
return zapcore.NewJSONEncoder(gceEncoderConfig)
} else {
return zapcore.NewConsoleEncoder(consoleEncoderConfig)
conf := consoleEncoderConfig
if isColorDisabled() {
conf.EncodeLevel = zapcore.CapitalLevelEncoder
}
return zapcore.NewConsoleEncoder(conf)
}
}

Expand Down Expand Up @@ -270,3 +274,7 @@ func (l *Logger) msg(msg string) string {
}
return p + msg + s
}

func isColorDisabled() bool {
return os.Getenv("NO_COLOR") != ""
}

0 comments on commit 402668d

Please sign in to comment.