From d4fd06c3dc6cd6d2dbd2bfebfee5bcb46a504851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Wed, 22 Feb 2017 14:10:07 +0200 Subject: all: blidly swap out glog to our log15, logs need rework --- internal/debug/api.go | 29 ++++++++++++++--------------- internal/debug/flags.go | 28 ++++++++++++++++------------ internal/debug/trace.go | 8 ++++---- internal/ethapi/api.go | 33 ++++++++++++++++----------------- 4 files changed, 50 insertions(+), 48 deletions(-) (limited to 'internal') 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 = (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 = "" diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 6b11cbc97..ca31c9f4b 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -36,8 +36,7 @@ import ( "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethdb" - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/logger/glog" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rpc" @@ -475,7 +474,7 @@ func (s *PublicBlockChainAPI) GetUncleByBlockNumberAndIndex(ctx context.Context, if block != nil { uncles := block.Uncles() if index >= hexutil.Uint(len(uncles)) { - glog.V(logger.Debug).Infof("uncle block on index %d not found for block #%d", index, blockNr) + log.Debug(fmt.Sprintf("uncle block on index %d not found for block #%d", index, blockNr)) return nil, nil } block = types.NewBlockWithHeader(uncles[index]) @@ -491,7 +490,7 @@ func (s *PublicBlockChainAPI) GetUncleByBlockHashAndIndex(ctx context.Context, b if block != nil { uncles := block.Uncles() if index >= hexutil.Uint(len(uncles)) { - glog.V(logger.Debug).Infof("uncle block on index %d not found for block %s", index, blockHash.Hex()) + log.Debug(fmt.Sprintf("uncle block on index %d not found for block %s", index, blockHash.Hex())) return nil, nil } block = types.NewBlockWithHeader(uncles[index]) @@ -577,7 +576,7 @@ type CallArgs struct { } func (s *PublicBlockChainAPI) doCall(ctx context.Context, args CallArgs, blockNr rpc.BlockNumber, vmCfg vm.Config) ([]byte, *big.Int, error) { - defer func(start time.Time) { glog.V(logger.Debug).Infof("call took %v", time.Since(start)) }(time.Now()) + defer func(start time.Time) { log.Debug(fmt.Sprintf("call took %v", time.Since(start))) }(time.Now()) state, header, err := s.b.StateAndHeaderByNumber(ctx, blockNr) if state == nil || err != nil { @@ -1003,7 +1002,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionByHash(ctx context.Context, txH var err error if tx, isPending, err = getTransaction(s.b.ChainDb(), s.b, txHash); err != nil { - glog.V(logger.Debug).Infof("%v\n", err) + log.Debug(fmt.Sprintf("%v\n", err)) return nil, nil } else if tx == nil { return nil, nil @@ -1015,7 +1014,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionByHash(ctx context.Context, txH blockHash, _, _, err := getTransactionBlockData(s.b.ChainDb(), txHash) if err != nil { - glog.V(logger.Debug).Infof("%v\n", err) + log.Debug(fmt.Sprintf("%v\n", err)) return nil, nil } @@ -1032,7 +1031,7 @@ func (s *PublicTransactionPoolAPI) GetRawTransactionByHash(ctx context.Context, var err error if tx, _, err = getTransaction(s.b.ChainDb(), s.b, txHash); err != nil { - glog.V(logger.Debug).Infof("%v\n", err) + log.Debug(fmt.Sprintf("%v\n", err)) return nil, nil } else if tx == nil { return nil, nil @@ -1045,19 +1044,19 @@ func (s *PublicTransactionPoolAPI) GetRawTransactionByHash(ctx context.Context, func (s *PublicTransactionPoolAPI) GetTransactionReceipt(txHash common.Hash) (map[string]interface{}, error) { receipt := core.GetReceipt(s.b.ChainDb(), txHash) if receipt == nil { - glog.V(logger.Debug).Infof("receipt not found for transaction %s", txHash.Hex()) + log.Debug(fmt.Sprintf("receipt not found for transaction %s", txHash.Hex())) return nil, nil } tx, _, err := getTransaction(s.b.ChainDb(), s.b, txHash) if err != nil { - glog.V(logger.Debug).Infof("%v\n", err) + log.Debug(fmt.Sprintf("%v\n", err)) return nil, nil } txBlock, blockIndex, index, err := getTransactionBlockData(s.b.ChainDb(), txHash) if err != nil { - glog.V(logger.Debug).Infof("%v\n", err) + log.Debug(fmt.Sprintf("%v\n", err)) return nil, nil } @@ -1160,9 +1159,9 @@ func submitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (c signer := types.MakeSigner(b.ChainConfig(), b.CurrentBlock().Number()) from, _ := types.Sender(signer, tx) addr := crypto.CreateAddress(from, tx.Nonce()) - glog.V(logger.Info).Infof("Tx(%s) created: %s\n", tx.Hash().Hex(), addr.Hex()) + log.Info(fmt.Sprintf("Tx(%s) created: %s\n", tx.Hash().Hex(), addr.Hex())) } else { - glog.V(logger.Info).Infof("Tx(%s) to: %s\n", tx.Hash().Hex(), tx.To().Hex()) + log.Info(fmt.Sprintf("Tx(%s) to: %s\n", tx.Hash().Hex(), tx.To().Hex())) } return tx.Hash(), nil } @@ -1214,9 +1213,9 @@ func (s *PublicTransactionPoolAPI) SendRawTransaction(ctx context.Context, encod return "", err } addr := crypto.CreateAddress(from, tx.Nonce()) - glog.V(logger.Info).Infof("Tx(%x) created: %x\n", tx.Hash(), addr) + log.Info(fmt.Sprintf("Tx(%x) created: %x\n", tx.Hash(), addr)) } else { - glog.V(logger.Info).Infof("Tx(%x) to: %x\n", tx.Hash(), tx.To()) + log.Info(fmt.Sprintf("Tx(%x) to: %x\n", tx.Hash(), tx.To())) } return tx.Hash().Hex(), nil @@ -1421,10 +1420,10 @@ func (api *PrivateDebugAPI) ChaindbCompact() error { return fmt.Errorf("chaindbCompact does not work for memory databases") } for b := byte(0); b < 255; b++ { - glog.V(logger.Info).Infof("compacting chain DB range 0x%0.2X-0x%0.2X", b, b+1) + log.Info(fmt.Sprintf("compacting chain DB range 0x%0.2X-0x%0.2X", b, b+1)) err := ldb.LDB().CompactRange(util.Range{Start: []byte{b}, Limit: []byte{b + 1}}) if err != nil { - glog.Errorf("compaction error: %v", err) + log.Error(fmt.Sprintf("compaction error: %v", err)) return err } } -- cgit v1.2.3