diff options
Diffstat (limited to 'internal')
-rw-r--r-- | internal/debug/flags.go | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/internal/debug/flags.go b/internal/debug/flags.go index 5eb58e9ee..7d7eba98a 100644 --- a/internal/debug/flags.go +++ b/internal/debug/flags.go @@ -95,7 +95,10 @@ var Flags = []cli.Flag{ memprofilerateFlag, blockprofilerateFlag, cpuprofileFlag, traceFlag, } -var glogger *log.GlogHandler +var ( + ostream log.Handler + glogger *log.GlogHandler +) func init() { usecolor := term.IsTty(os.Stderr.Fd()) && os.Getenv("TERM") != "dumb" @@ -103,14 +106,26 @@ func init() { if usecolor { output = colorable.NewColorableStderr() } - glogger = log.NewGlogHandler(log.StreamHandler(output, log.TerminalFormat(usecolor))) + ostream = log.StreamHandler(output, log.TerminalFormat(usecolor)) + glogger = log.NewGlogHandler(ostream) } // Setup initializes profiling and logging based on the CLI flags. // It should be called as early as possible in the program. -func Setup(ctx *cli.Context) error { +func Setup(ctx *cli.Context, logdir string) error { // logging log.PrintOrigins(ctx.GlobalBool(debugFlag.Name)) + if logdir != "" { + rfh, err := log.RotatingFileHandler( + logdir, + 262144, + log.JSONFormatOrderedEx(false, true), + ) + if err != nil { + return err + } + glogger.SetHandler(log.MultiHandler(ostream, rfh)) + } glogger.Verbosity(log.Lvl(ctx.GlobalInt(verbosityFlag.Name))) glogger.Vmodule(ctx.GlobalString(vmoduleFlag.Name)) glogger.BacktraceAt(ctx.GlobalString(backtraceAtFlag.Name)) |