Skip to content

Commit ee4cba7

Browse files
committed
Add --logfile-path flag to write logs to file
1 parent 9f93b90 commit ee4cba7

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pkg/log/log.go

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
var (
2727
lvlString = "info"
2828
logJSON = false
29+
logfilePath = ""
2930
config *zap.Config
3031
mu sync.Mutex
3132
glogVerbosity string
@@ -34,6 +35,7 @@ var (
3435
func init() {
3536
flag.StringVar(&lvlString, "log-level", lvlString, "Adjusts the level of the logs that will be omitted.")
3637
flag.BoolVar(&logJSON, "log-json", logJSON, "Log in json format.")
38+
flag.StringVar(&logfilePath, "logfile-path", "", "If specified, write log messages to a file at this path.")
3739
_ = flag.String("v", "", "For glog backwards compat. Does nothing.")
3840
}
3941

@@ -69,6 +71,10 @@ func Logger() *zap.Logger {
6971
cfg = zap.NewProductionConfig()
7072
}
7173

74+
if len(logfilePath) > 0 {
75+
cfg.OutputPaths = append(cfg.OutputPaths, logfilePath)
76+
}
77+
7278
if config == nil {
7379
config = &cfg
7480
if level, err := levelFromString(lvlString); err == nil {

0 commit comments

Comments
 (0)