Commit ac69aba5 authored by Brian Tiger Chow's avatar Brian Tiger Chow

feat(2/main) configure event logger

License: MIT
Signed-off-by: default avatarBrian Tiger Chow <brian@perfmode.com>

# TYPES
# feat
# fix
# docs
# style (formatting, missing semi colons, etc; no code change):
# refactor
# test (adding missing tests, refactoring tests; no production code change)
# chore (updating grunt tasks etc; no production code change)
Signed-off-by: default avatarBrian Tiger Chow <brian.holderchow@gmail.com>
parent be62b765
......@@ -232,6 +232,17 @@ func callPreCommandHooks(command cmdDetails, req cmds.Request, root *cmds.Comman
}
}
// When the upcoming command may use the config and repo, we know it's safe
// for the log config hook to touch the config/repo
if command.usesConfigAsInput() && command.usesRepo() {
log.Debug("Calling hook: Configure Event Logger")
cfg, err := req.Context().GetConfig()
if err != nil {
return err
}
configureEventLogger(cfg)
}
return nil
}
......@@ -481,3 +492,24 @@ func allInterruptSignals() chan os.Signal {
syscall.SIGTERM, syscall.SIGQUIT)
return sigc
}
func configureEventLogger(config *config.Config) error {
if u.Debug {
elog.Configure(elog.LevelDebug)
} else {
elog.Configure(elog.LevelInfo)
}
elog.Configure(elog.LdJSONFormatter)
rotateConf := elog.LogRotatorConfig{
Filename: config.Logs.Filename,
MaxSizeMB: config.Logs.MaxSizeMB,
MaxBackups: config.Logs.MaxBackups,
MaxAgeDays: config.Logs.MaxAgeDays,
}
elog.Configure(elog.OutputRotatingLogFile(rotateConf))
return nil
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment