aboutsummaryrefslogtreecommitdiffstats
path: root/internal
diff options
context:
space:
mode:
authorKurkó Mihály <kurkomisi@users.noreply.github.com>2018-07-11 15:59:04 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-07-11 15:59:04 +0800
commita9835c1816bc49ee54c82b4f2a5b05cbcd89881b (patch)
treee1badefd627aa3a7c4e1937eab22b8fe3eb204d1 /internal
parent2eedbe799f5eb8766e4808d8a1810cc1c90c4b93 (diff)
downloaddexon-a9835c1816bc49ee54c82b4f2a5b05cbcd89881b.tar
dexon-a9835c1816bc49ee54c82b4f2a5b05cbcd89881b.tar.gz
dexon-a9835c1816bc49ee54c82b4f2a5b05cbcd89881b.tar.bz2
dexon-a9835c1816bc49ee54c82b4f2a5b05cbcd89881b.tar.lz
dexon-a9835c1816bc49ee54c82b4f2a5b05cbcd89881b.tar.xz
dexon-a9835c1816bc49ee54c82b4f2a5b05cbcd89881b.tar.zst
dexon-a9835c1816bc49ee54c82b4f2a5b05cbcd89881b.zip
cmd, dashboard, log: log collection and exploration (#17097)
* cmd, dashboard, internal, log, node: logging feature * cmd, dashboard, internal, log: requested changes * dashboard, vendor: gofmt, govendor, use vendored file watcher * dashboard, log: gofmt -s -w, goimports * dashboard, log: gosimple
Diffstat (limited to 'internal')
-rw-r--r--internal/debug/flags.go21
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))