diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-02-22 20:10:07 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2017-02-23 18:16:44 +0800 |
commit | d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851 (patch) | |
tree | 17c93170551d3eeabe2935de1765f157007f0dc2 /internal/debug | |
parent | 47af53f9aaf9aa7b12cd976eb150ccf3d64da6fd (diff) | |
download | dexon-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.tar.gz dexon-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.tar.zst dexon-d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851.zip |
all: blidly swap out glog to our log15, logs need rework
Diffstat (limited to 'internal/debug')
-rw-r--r-- | internal/debug/api.go | 29 | ||||
-rw-r--r-- | internal/debug/flags.go | 28 | ||||
-rw-r--r-- | internal/debug/trace.go | 8 |
3 files changed, 34 insertions, 31 deletions
diff --git a/internal/debug/api.go b/internal/debug/api.go index 96091541b..01126b41b 100644 --- a/internal/debug/api.go +++ b/internal/debug/api.go @@ -22,6 +22,7 @@ package debug import ( "errors" + "fmt" "io" "os" "os/user" @@ -33,8 +34,7 @@ import ( "sync" "time" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" ) // Handler is the global debugging handler. @@ -51,23 +51,22 @@ type HandlerT struct { traceFile string } -// Verbosity sets the glog verbosity ceiling. -// The verbosity of individual packages and source files -// can be raised using Vmodule. +// Verbosity sets the log verbosity ceiling. The verbosity of individual packages +// and source files can be raised using Vmodule. func (*HandlerT) Verbosity(level int) { - glog.SetV(level) + glogger.Verbosity(log.Lvl(level)) } -// Vmodule sets the glog verbosity pattern. See package -// glog for details on pattern syntax. +// Vmodule sets the log verbosity pattern. See package log for details on the +// pattern syntax. func (*HandlerT) Vmodule(pattern string) error { - return glog.GetVModule().Set(pattern) + return glogger.Vmodule(pattern) } -// BacktraceAt sets the glog backtrace location. -// See package glog for details on pattern syntax. +// BacktraceAt sets the log backtrace location. See package log for details on +// the pattern syntax. func (*HandlerT) BacktraceAt(location string) error { - return glog.GetTraceLocation().Set(location) + return glogger.BacktraceAt(location) } // MemStats returns detailed runtime memory statistics. @@ -112,7 +111,7 @@ func (h *HandlerT) StartCPUProfile(file string) error { } h.cpuW = f h.cpuFile = file - glog.V(logger.Info).Infoln("CPU profiling started, writing to", h.cpuFile) + log.Info(fmt.Sprint("CPU profiling started, writing to", h.cpuFile)) return nil } @@ -124,7 +123,7 @@ func (h *HandlerT) StopCPUProfile() error { if h.cpuW == nil { return errors.New("CPU profiling not in progress") } - glog.V(logger.Info).Infoln("done writing CPU profile to", h.cpuFile) + log.Info(fmt.Sprint("done writing CPU profile to", h.cpuFile)) h.cpuW.Close() h.cpuW = nil h.cpuFile = "" @@ -180,7 +179,7 @@ func (*HandlerT) Stacks() string { func writeProfile(name, file string) error { p := pprof.Lookup(name) - glog.V(logger.Info).Infof("writing %d %s profile records to %s", p.Count(), name, file) + log.Info(fmt.Sprintf("writing %d %s profile records to %s", p.Count(), name, file)) f, err := os.Create(expandHome(file)) if err != nil { return err diff --git a/internal/debug/flags.go b/internal/debug/flags.go index d7bbfae1e..780aa1647 100644 --- a/internal/debug/flags.go +++ b/internal/debug/flags.go @@ -20,28 +20,28 @@ import ( "fmt" "net/http" _ "net/http/pprof" + "os" "runtime" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" "gopkg.in/urfave/cli.v1" ) var ( - verbosityFlag = cli.GenericFlag{ + verbosityFlag = cli.IntFlag{ Name: "verbosity", Usage: "Logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4=core, 5=debug, 6=detail", - Value: glog.GetVerbosity(), + Value: 3, } - vmoduleFlag = cli.GenericFlag{ + vmoduleFlag = cli.StringFlag{ Name: "vmodule", Usage: "Per-module verbosity: comma-separated list of <pattern>=<level> (e.g. eth/*=6,p2p=5)", - Value: glog.GetVModule(), + Value: "", } - backtraceAtFlag = cli.GenericFlag{ + backtraceAtFlag = cli.StringFlag{ Name: "backtrace", Usage: "Request a stack trace at a specific logging statement (e.g. \"block.go:271\")", - Value: glog.GetTraceLocation(), + Value: "", } pprofFlag = cli.BoolFlag{ Name: "pprof", @@ -83,12 +83,16 @@ var Flags = []cli.Flag{ memprofilerateFlag, blockprofilerateFlag, cpuprofileFlag, traceFlag, } +var glogger = log.NewGlogHandler(log.StreamHandler(os.Stderr, log.TerminalFormat())) + // 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 { // logging - glog.CopyStandardLogTo("INFO") - glog.SetToStderr(true) + glogger.Verbosity(log.Lvl(ctx.GlobalInt(verbosityFlag.Name))) + glogger.Vmodule(ctx.GlobalString(vmoduleFlag.Name)) + glogger.BacktraceAt(ctx.GlobalString(backtraceAtFlag.Name)) + log.Root().SetHandler(glogger) // profiling, tracing runtime.MemProfileRate = ctx.GlobalInt(memprofilerateFlag.Name) @@ -108,8 +112,8 @@ func Setup(ctx *cli.Context) error { if ctx.GlobalBool(pprofFlag.Name) { address := fmt.Sprintf("%s:%d", ctx.GlobalString(pprofAddrFlag.Name), ctx.GlobalInt(pprofPortFlag.Name)) go func() { - glog.V(logger.Info).Infof("starting pprof server at http://%s/debug/pprof", address) - glog.Errorln(http.ListenAndServe(address, nil)) + log.Info(fmt.Sprintf("starting pprof server at http://%s/debug/pprof", address)) + log.Error(fmt.Sprint(http.ListenAndServe(address, nil))) }() } return nil diff --git a/internal/debug/trace.go b/internal/debug/trace.go index c0cf921ff..5e4b9df84 100644 --- a/internal/debug/trace.go +++ b/internal/debug/trace.go @@ -20,11 +20,11 @@ package debug import ( "errors" + "fmt" "os" "runtime/trace" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" ) // StartGoTrace turns on tracing, writing to the given file. @@ -44,7 +44,7 @@ func (h *HandlerT) StartGoTrace(file string) error { } h.traceW = f h.traceFile = file - glog.V(logger.Info).Infoln("trace started, writing to", h.traceFile) + log.Info(fmt.Sprint("trace started, writing to", h.traceFile)) return nil } @@ -56,7 +56,7 @@ func (h *HandlerT) StopGoTrace() error { if h.traceW == nil { return errors.New("trace not in progress") } - glog.V(logger.Info).Infoln("done writing trace to", h.traceFile) + log.Info(fmt.Sprint("done writing trace to", h.traceFile)) h.traceW.Close() h.traceW = nil h.traceFile = "" |