@cryptotaxi247 / kubo / commits / ac69aba56

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>

Brian Tiger Chow committed Nov 16, 2014 at 03:58 UTC ac69aba56188280bcc09cb4c6188dcee8426d06e
1 file changed +32
cmd/ipfs2/main.go
+32
@@ -232,6 +232,17 @@ func callPreCommandHooks(command cmdDetails, req cmds.Request, root *cmds.Comman
232 }
233 }
234
235 + // When the upcoming command may use the config and repo, we know it's safe
236 + // for the log config hook to touch the config/repo
237 + if command.usesConfigAsInput() && command.usesRepo() {
238 + log.Debug("Calling hook: Configure Event Logger")
239 + cfg, err := req.Context().GetConfig()
240 + if err != nil {
241 + return err
242 + }
243 + configureEventLogger(cfg)
244 + }
245 +
246 return nil
247 }
248
@@ -481,3 +492,24 @@ func allInterruptSignals() chan os.Signal {
492 syscall.SIGTERM, syscall.SIGQUIT)
493 return sigc
494 }
495 +
496 +func configureEventLogger(config *config.Config) error {
497 +
498 + if u.Debug {
499 + elog.Configure(elog.LevelDebug)
500 + } else {
501 + elog.Configure(elog.LevelInfo)
502 + }
503 +
504 + elog.Configure(elog.LdJSONFormatter)
505 +
506 + rotateConf := elog.LogRotatorConfig{
507 + Filename: config.Logs.Filename,
508 + MaxSizeMB: config.Logs.MaxSizeMB,
509 + MaxBackups: config.Logs.MaxBackups,
510 + MaxAgeDays: config.Logs.MaxAgeDays,
511 + }
512 +
513 + elog.Configure(elog.OutputRotatingLogFile(rotateConf))
514 + return nil
515 +}