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

Commit 67e8574

Browse files
committed
problem: configure flags and default log settings
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
1 parent 94537d6 commit 67e8574

File tree

5 files changed

+103
-14
lines changed

5 files changed

+103
-14
lines changed

cmd/geth/flags.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,25 +140,39 @@ var (
140140
}
141141

142142
// logging and debug settings
143+
NeckbeardFlag = cli.BoolFlag{
144+
Name: "neckbeard",
145+
Usage: "Use verbose->stderr defaults for logging (verbosity=5,log-status='sync=60')",
146+
}
143147
VerbosityFlag = cli.GenericFlag{
144148
Name: "verbosity",
145149
Usage: "Logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4=core, 5=debug, 6=detail",
146150
Value: glog.GetVerbosity(),
147151
}
152+
DisplayFlag = cli.IntFlag{
153+
Name: "display",
154+
Usage: "Display verbosity: 0=silent, 1=basics, 2=status, 3=events",
155+
Value: 2,
156+
}
148157
VModuleFlag = cli.GenericFlag{
149158
Name: "vmodule",
150159
Usage: "Per-module verbosity: comma-separated list of <pattern>=<level> (e.g. eth/*=6,p2p=5)",
151160
Value: glog.GetVModule(),
152161
}
162+
VerbosityTraceFloorFlag = cli.IntFlag{
163+
Name: "verbosity-trace-floor",
164+
Usage: "Floor verbosity level at which to include file traces on log lines.",
165+
Value: 0,
166+
}
153167
LogDirFlag = DirectoryFlag{
154168
Name: "log-dir,logdir",
155169
Usage: "Directory in which to write log files.",
156-
Value: DirectoryString{filepath.Join(common.DefaultDataDir(), "logs")},
170+
Value: DirectoryString{filepath.Join(common.DefaultDataDir(), "mainnet", "log")},
157171
}
158172
LogStatusFlag = cli.StringFlag{
159173
Name: "log-status",
160-
Usage: `Toggle interval-based STATUS logs: comma-separated list of <pattern>=<interval>`,
161-
Value: "sync=60",
174+
Usage: `Toggle interval-based STATUS logs: comma-separated list of <pattern>=<interval>. Use 'off' to disable entirely.'`,
175+
Value: "sync=30",
162176
}
163177
MLogFlag = cli.StringFlag{
164178
Name: "mlog",
@@ -168,8 +182,7 @@ var (
168182
MLogDirFlag = DirectoryFlag{
169183
Name: "mlog-dir",
170184
Usage: "Directory in which to write machine log files",
171-
// TODO: move to chain-subdir?
172-
Value: DirectoryString{filepath.Join(common.DefaultDataDir(), "mlogs")},
185+
Value: DirectoryString{filepath.Join(common.DefaultDataDir(), "mainnet", "mlogs")},
173186
}
174187
MLogComponentsFlag = cli.StringFlag{
175188
Name: "mlog-components",

cmd/geth/main.go

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"os"
2424
"path/filepath"
2525
"runtime"
26+
"time"
2627

2728
"gopkg.in/urfave/cli.v1"
2829

@@ -171,8 +172,11 @@ func makeCLIApp() (app *cli.App) {
171172
TestNetFlag,
172173
NetworkIdFlag,
173174
RPCCORSDomainFlag,
175+
NeckbeardFlag,
174176
VerbosityFlag,
177+
DisplayFlag,
175178
VModuleFlag,
179+
VerbosityTraceFloorFlag,
176180
LogDirFlag,
177181
LogStatusFlag,
178182
MLogFlag,
@@ -223,18 +227,69 @@ func makeCLIApp() (app *cli.App) {
223227

224228
runtime.GOMAXPROCS(runtime.NumCPU())
225229

230+
glog.MaxSize = 50 * 1024 * 1024
231+
glog.MinSize = 1 * 1024 * 1024
232+
glog.MaxTotalSize = 1024 * 1024 * 1024
233+
glog.Compress = true
234+
glog.RotationInterval = glog.Hourly
235+
glog.MaxAge = 24 * time.Hour
236+
226237
glog.CopyStandardLogTo("INFO")
227238

239+
// log.Println("Writing logs to ", logDir)
240+
// Turn on only file logging, disabling logging(T).toStderr and logging(T).alsoToStdErr
241+
glog.SetToStderr(false)
242+
glog.SetAlsoToStderr(false)
243+
244+
// Set up file logging.
245+
logDir := filepath.Join(MustMakeChainDataDir(ctx), "log")
228246
if ctx.GlobalIsSet(aliasableName(LogDirFlag.Name, ctx)) {
229-
if p := ctx.GlobalString(aliasableName(LogDirFlag.Name, ctx)); p != "" {
230-
if e := os.MkdirAll(p, os.ModePerm); e != nil {
231-
return e
232-
}
233-
glog.SetLogDir(p)
234-
glog.SetAlsoToStderr(true)
247+
ld := ctx.GlobalString(aliasableName(LogDirFlag.Name, ctx))
248+
ldAbs, err := filepath.Abs(ld)
249+
if err != nil {
250+
glog.Fatalln(err)
251+
}
252+
logDir = ldAbs
253+
}
254+
// Ensure mkdir -p
255+
if e := os.MkdirAll(logDir, os.ModePerm); e != nil {
256+
return e
257+
}
258+
// Set log dir.
259+
// GOTCHA: There may be NO glog.V logs called before this is set.
260+
// Otherwise everything will get all fucked and there will be no logs.
261+
glog.SetLogDir(logDir)
262+
263+
if ctx.GlobalIsSet(DisplayFlag.Name) {
264+
i := ctx.GlobalInt(DisplayFlag.Name)
265+
if i > 3 {
266+
return fmt.Errorf("Error: --%s level must be 0 <= i <= 3, got: %d", DisplayFlag.Name, i)
235267
}
236-
} else {
237-
glog.SetToStderr(true)
268+
glog.SetD(i)
269+
}
270+
271+
if ctx.GlobalBool(NeckbeardFlag.Name) {
272+
glog.SetD(0)
273+
// Allow manual overrides
274+
if !ctx.GlobalIsSet(LogStatusFlag.Name) {
275+
ctx.Set(LogStatusFlag.Name, "sync=60") // set log-status interval
276+
}
277+
if !ctx.GlobalIsSet(VerbosityTraceFloorFlag.Name) {
278+
glog.SetVTraceThreshold(0)
279+
}
280+
if !ctx.GlobalIsSet(VerbosityFlag.Name) {
281+
glog.SetV(5)
282+
}
283+
glog.SetAlsoToStderr(true)
284+
}
285+
// If --log-status not set, set default 60s interval
286+
if !ctx.GlobalIsSet(LogStatusFlag.Name) {
287+
ctx.Set(LogStatusFlag.Name, "sync=30")
288+
}
289+
if ctx.GlobalIsSet(VerbosityTraceFloorFlag.Name) {
290+
val := ctx.GlobalInt(VerbosityTraceFloorFlag.Name)
291+
log.Println("--verbosity-trace-floor", "val", val)
292+
glog.SetVTraceThreshold(val)
238293
}
239294

240295
if s := ctx.String("metrics"); s != "" {
@@ -294,8 +349,9 @@ func main() {
294349
func geth(ctx *cli.Context) error {
295350
n := MakeSystemNode(Version, ctx)
296351
ethe := startNode(ctx, n)
352+
n.EventMux()
297353

298-
if ctx.GlobalIsSet(LogStatusFlag.Name) {
354+
if ctx.GlobalString(LogStatusFlag.Name) != "off" {
299355
dispatchStatusLogs(ctx, ethe)
300356
}
301357

cmd/geth/usage.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,10 @@ var AppHelpFlagGroups = []flagGroup{
136136
{
137137
Name: "LOGGING AND DEBUGGING",
138138
Flags: []cli.Flag{
139+
NeckbeardFlag,
139140
VerbosityFlag,
140141
VModuleFlag,
142+
VerbosityTraceFloorFlag,
141143
LogDirFlag,
142144
LogStatusFlag,
143145
MLogFlag,

eth/api.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,6 +1772,18 @@ func (api *PublicDebugAPI) Vmodule(s string) (string, error) {
17721772
return glog.GetVModule().String(), err
17731773
}
17741774

1775+
func (api *PublicDebugAPI) VerbosityTraceFloor(n uint64) (int, error) {
1776+
nint := int(n)
1777+
if nint == 0 {
1778+
return int(*glog.GetVTraceThreshold()), nil
1779+
}
1780+
if nint <= logger.Detail || nint == logger.Ridiculousness {
1781+
glog.SetVTraceThreshold(nint)
1782+
return int(*glog.GetVTraceThreshold()), nil
1783+
}
1784+
return -1, errors.New("invalid logging level")
1785+
}
1786+
17751787
// ExecutionResult groups all structured logs emitted by the EVM
17761788
// while replaying a transaction in debug mode as well as the amount of
17771789
// gas used and the return value

internal/web3ext/web3ext.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ web3._extend({
191191
params: 1,
192192
inputFormatter: [web3._extend.formatters.inputOptionalNumberFormatter]
193193
}),
194+
new web3._extend.Method({
195+
name: 'verbosityTraceFloor',
196+
call: 'debug_verbosityTraceFloor',
197+
params: 1,
198+
inputFormatter: [web3._extend.formatters.inputOptionalNumberFormatter]
199+
}),
194200
new web3._extend.Method({
195201
name: 'vmodule',
196202
call: 'debug_vmodule',

0 commit comments

Comments
 (0)