all: blidly swap out glog to our log15, logs need rework

This commit is contained in:
Péter Szilágyi
2017-02-22 14:10:07 +02:00
parent 47af53f9aa
commit d4fd06c3dc
147 changed files with 1546 additions and 3693 deletions

View File

@ -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

View File

@ -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

View File

@ -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 = ""