Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Commit

Permalink
problem: configure flags and default log settings
Browse files Browse the repository at this point in the history
solution:
use display logs as default for stderr, sending glog.V logs to file
set global verbosity for glog.V -> logger.Debug (Level 5), noting that --verbosity flag can still override
use --neckbeard flag to enable sending debug logs to stderr INSTEAD of display logs
expose VerbosityTraceFloor as debug API <-- note: this to be REMOVED
  • Loading branch information
whilei committed Dec 6, 2017
1 parent 647d7c6 commit 14e35cd
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 14 deletions.
23 changes: 18 additions & 5 deletions cmd/geth/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,25 +140,39 @@ var (
}

// logging and debug settings
NeckbeardFlag = cli.BoolFlag{
Name: "neckbeard",
Usage: "Use verbose->stderr defaults for logging (verbosity=5,log-status='sync=60')",
}
VerbosityFlag = cli.GenericFlag{
Name: "verbosity",
Usage: "Logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4=core, 5=debug, 6=detail",
Value: glog.GetVerbosity(),
}
DisplayFlag = cli.IntFlag{
Name: "display",
Usage: "Display verbosity: 0=silent, 1=basics, 2=status, 3=events",
Value: 2,
}
VModuleFlag = cli.GenericFlag{
Name: "vmodule",
Usage: "Per-module verbosity: comma-separated list of <pattern>=<level> (e.g. eth/*=6,p2p=5)",
Value: glog.GetVModule(),
}
VerbosityTraceFloorFlag = cli.IntFlag{
Name: "verbosity-trace-floor",
Usage: "Floor verbosity level at which to include file traces on log lines.",
Value: 0,
}
LogDirFlag = DirectoryFlag{
Name: "log-dir,logdir",
Usage: "Directory in which to write log files.",
Value: DirectoryString{filepath.Join(common.DefaultDataDir(), "logs")},
Value: DirectoryString{filepath.Join(common.DefaultDataDir(), "mainnet", "log")},
}
LogStatusFlag = cli.StringFlag{
Name: "log-status",
Usage: `Toggle interval-based STATUS logs: comma-separated list of <pattern>=<interval>`,
Value: "sync=60",
Usage: `Toggle interval-based STATUS logs: comma-separated list of <pattern>=<interval>. Use 'off' to disable entirely.'`,
Value: "sync=30",
}
MLogFlag = cli.StringFlag{
Name: "mlog",
Expand All @@ -168,8 +182,7 @@ var (
MLogDirFlag = DirectoryFlag{
Name: "mlog-dir",
Usage: "Directory in which to write machine log files",
// TODO: move to chain-subdir?
Value: DirectoryString{filepath.Join(common.DefaultDataDir(), "mlogs")},
Value: DirectoryString{filepath.Join(common.DefaultDataDir(), "mainnet", "mlogs")},
}
MLogComponentsFlag = cli.StringFlag{
Name: "mlog-components",
Expand Down
74 changes: 65 additions & 9 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"
"path/filepath"
"runtime"
"time"

"gopkg.in/urfave/cli.v1"

Expand Down Expand Up @@ -171,8 +172,11 @@ func makeCLIApp() (app *cli.App) {
TestNetFlag,
NetworkIdFlag,
RPCCORSDomainFlag,
NeckbeardFlag,
VerbosityFlag,
DisplayFlag,
VModuleFlag,
VerbosityTraceFloorFlag,
LogDirFlag,
LogStatusFlag,
MLogFlag,
Expand Down Expand Up @@ -223,18 +227,69 @@ func makeCLIApp() (app *cli.App) {

runtime.GOMAXPROCS(runtime.NumCPU())

glog.MaxSize = 50 * 1024 * 1024
glog.MinSize = 1 * 1024 * 1024
glog.MaxTotalSize = 1024 * 1024 * 1024
glog.Compress = true
glog.RotationInterval = glog.Hourly
glog.MaxAge = 24 * time.Hour

glog.CopyStandardLogTo("INFO")

// log.Println("Writing logs to ", logDir)
// Turn on only file logging, disabling logging(T).toStderr and logging(T).alsoToStdErr
glog.SetToStderr(false)
glog.SetAlsoToStderr(false)

// Set up file logging.
logDir := filepath.Join(MustMakeChainDataDir(ctx), "log")
if ctx.GlobalIsSet(aliasableName(LogDirFlag.Name, ctx)) {
if p := ctx.GlobalString(aliasableName(LogDirFlag.Name, ctx)); p != "" {
if e := os.MkdirAll(p, os.ModePerm); e != nil {
return e
}
glog.SetLogDir(p)
glog.SetAlsoToStderr(true)
ld := ctx.GlobalString(aliasableName(LogDirFlag.Name, ctx))
ldAbs, err := filepath.Abs(ld)
if err != nil {
glog.Fatalln(err)
}
logDir = ldAbs
}
// Ensure mkdir -p
if e := os.MkdirAll(logDir, os.ModePerm); e != nil {
return e
}
// Set log dir.
// GOTCHA: There may be NO glog.V logs called before this is set.
// Otherwise everything will get all fucked and there will be no logs.
glog.SetLogDir(logDir)

if ctx.GlobalIsSet(DisplayFlag.Name) {
i := ctx.GlobalInt(DisplayFlag.Name)
if i > 3 {
return fmt.Errorf("Error: --%s level must be 0 <= i <= 3, got: %d", DisplayFlag.Name, i)
}
} else {
glog.SetToStderr(true)
glog.SetD(i)
}

if ctx.GlobalBool(NeckbeardFlag.Name) {
glog.SetD(0)
// Allow manual overrides
if !ctx.GlobalIsSet(LogStatusFlag.Name) {
ctx.Set(LogStatusFlag.Name, "sync=60") // set log-status interval
}
if !ctx.GlobalIsSet(VerbosityTraceFloorFlag.Name) {
glog.SetVTraceThreshold(0)
}
if !ctx.GlobalIsSet(VerbosityFlag.Name) {
glog.SetV(5)
}
glog.SetAlsoToStderr(true)
}
// If --log-status not set, set default 60s interval
if !ctx.GlobalIsSet(LogStatusFlag.Name) {
ctx.Set(LogStatusFlag.Name, "sync=30")
}
if ctx.GlobalIsSet(VerbosityTraceFloorFlag.Name) {
val := ctx.GlobalInt(VerbosityTraceFloorFlag.Name)
log.Println("--verbosity-trace-floor", "val", val)
glog.SetVTraceThreshold(val)
}

if s := ctx.String("metrics"); s != "" {
Expand Down Expand Up @@ -294,8 +349,9 @@ func main() {
func geth(ctx *cli.Context) error {
n := MakeSystemNode(Version, ctx)
ethe := startNode(ctx, n)
n.EventMux()

if ctx.GlobalIsSet(LogStatusFlag.Name) {
if ctx.GlobalString(LogStatusFlag.Name) != "off" {
dispatchStatusLogs(ctx, ethe)
}

Expand Down
2 changes: 2 additions & 0 deletions cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ var AppHelpFlagGroups = []flagGroup{
{
Name: "LOGGING AND DEBUGGING",
Flags: []cli.Flag{
NeckbeardFlag,
VerbosityFlag,
VModuleFlag,
VerbosityTraceFloorFlag,
LogDirFlag,
LogStatusFlag,
MLogFlag,
Expand Down
12 changes: 12 additions & 0 deletions eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1772,6 +1772,18 @@ func (api *PublicDebugAPI) Vmodule(s string) (string, error) {
return glog.GetVModule().String(), err
}

func (api *PublicDebugAPI) VerbosityTraceFloor(n uint64) (int, error) {
nint := int(n)
if nint == 0 {
return int(*glog.GetVTraceThreshold()), nil
}
if nint <= logger.Detail || nint == logger.Ridiculousness {
glog.SetVTraceThreshold(nint)
return int(*glog.GetVTraceThreshold()), nil
}
return -1, errors.New("invalid logging level")
}

// ExecutionResult groups all structured logs emitted by the EVM
// while replaying a transaction in debug mode as well as the amount of
// gas used and the return value
Expand Down
6 changes: 6 additions & 0 deletions internal/web3ext/web3ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ web3._extend({
params: 1,
inputFormatter: [web3._extend.formatters.inputOptionalNumberFormatter]
}),
new web3._extend.Method({
name: 'verbosityTraceFloor',
call: 'debug_verbosityTraceFloor',
params: 1,
inputFormatter: [web3._extend.formatters.inputOptionalNumberFormatter]
}),
new web3._extend.Method({
name: 'vmodule',
call: 'debug_vmodule',
Expand Down

0 comments on commit 14e35cd

Please sign in to comment.