mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-04 15:58:13 +08:00
feat(2/main) configure event logger
License: MIT Signed-off-by: Brian 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: Brian Tiger Chow <brian.holderchow@gmail.com>
This commit is contained in:
parent
be62b76516
commit
ac69aba561
@ -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
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user