@@ -41,22 +41,22 @@ var (
4141 Usage : "Logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=detail" ,
4242 Value : 3 ,
4343 }
44- logjsonFlag = cli.BoolFlag {
45- Name : "log.json" ,
46- Usage : "Format logs with JSON" ,
47- }
4844 vmoduleFlag = cli.StringFlag {
4945 Name : "vmodule" ,
5046 Usage : "Per-module verbosity: comma-separated list of <pattern>=<level> (e.g. eth/*=5,p2p=4)" ,
5147 Value : "" ,
5248 }
49+ logjsonFlag = cli.BoolFlag {
50+ Name : "log.json" ,
51+ Usage : "Format logs with JSON" ,
52+ }
5353 backtraceAtFlag = cli.StringFlag {
54- Name : "backtrace" ,
54+ Name : "log. backtrace" ,
5555 Usage : "Request a stack trace at a specific logging statement (e.g. \" block.go:271\" )" ,
5656 Value : "" ,
5757 }
5858 debugFlag = cli.BoolFlag {
59- Name : "debug" ,
59+ Name : "log. debug" ,
6060 Usage : "Prepends log messages with call-site location (file and line number)" ,
6161 }
6262 pprofFlag = cli.BoolFlag {
@@ -90,18 +90,69 @@ var (
9090 Name : "trace" ,
9191 Usage : "Write execution trace to the given file" ,
9292 }
93+ // (Deprecated April 2020)
94+ legacyPprofPortFlag = cli.IntFlag {
95+ Name : "pprofport" ,
96+ Usage : "pprof HTTP server listening port (deprecated, use --pprof.port)" ,
97+ Value : 6060 ,
98+ }
99+ legacyPprofAddrFlag = cli.StringFlag {
100+ Name : "pprofaddr" ,
101+ Usage : "pprof HTTP server listening interface (deprecated, use --pprof.addr)" ,
102+ Value : "127.0.0.1" ,
103+ }
104+ legacyMemprofilerateFlag = cli.IntFlag {
105+ Name : "memprofilerate" ,
106+ Usage : "Turn on memory profiling with the given rate (deprecated, use --pprof.memprofilerate)" ,
107+ Value : runtime .MemProfileRate ,
108+ }
109+ legacyBlockprofilerateFlag = cli.IntFlag {
110+ Name : "blockprofilerate" ,
111+ Usage : "Turn on block profiling with the given rate (deprecated, use --pprof.blockprofilerate)" ,
112+ }
113+ legacyCpuprofileFlag = cli.StringFlag {
114+ Name : "cpuprofile" ,
115+ Usage : "Write CPU profile to the given file (deprecated, use --pprof.cpuprofile)" ,
116+ }
117+ legacyBacktraceAtFlag = cli.StringFlag {
118+ Name : "backtrace" ,
119+ Usage : "Request a stack trace at a specific logging statement (e.g. \" block.go:271\" ) (deprecated, use --log.backtrace)" ,
120+ Value : "" ,
121+ }
122+ legacyDebugFlag = cli.BoolFlag {
123+ Name : "debug" ,
124+ Usage : "Prepends log messages with call-site location (file and line number) (deprecated, use --log.debug)" ,
125+ }
93126)
94127
95128// Flags holds all command-line flags required for debugging.
96129var Flags = []cli.Flag {
97- verbosityFlag , logjsonFlag , vmoduleFlag , backtraceAtFlag , debugFlag ,
98- pprofFlag , pprofAddrFlag , pprofPortFlag , memprofilerateFlag ,
99- blockprofilerateFlag , cpuprofileFlag , traceFlag ,
130+ verbosityFlag ,
131+ vmoduleFlag ,
132+ logjsonFlag ,
133+ backtraceAtFlag ,
134+ debugFlag ,
135+ pprofFlag ,
136+ pprofAddrFlag ,
137+ pprofPortFlag ,
138+ memprofilerateFlag ,
139+ blockprofilerateFlag ,
140+ cpuprofileFlag ,
141+ traceFlag ,
100142}
101143
102- var (
103- glogger * log.GlogHandler
104- )
144+ // This is the list of deprecated debugging flags.
145+ var DeprecatedFlags = []cli.Flag {
146+ legacyPprofPortFlag ,
147+ legacyPprofAddrFlag ,
148+ legacyMemprofilerateFlag ,
149+ legacyBlockprofilerateFlag ,
150+ legacyCpuprofileFlag ,
151+ legacyBacktraceAtFlag ,
152+ legacyDebugFlag ,
153+ }
154+
155+ var glogger * log.GlogHandler
105156
106157func init () {
107158 glogger = log .NewGlogHandler (log .StreamHandler (os .Stderr , log .TerminalFormat (false )))
@@ -124,17 +175,54 @@ func Setup(ctx *cli.Context) error {
124175 ostream = log .StreamHandler (output , log .TerminalFormat (usecolor ))
125176 }
126177 glogger .SetHandler (ostream )
178+
127179 // logging
128- log .PrintOrigins (ctx .GlobalBool (debugFlag .Name ))
129- glogger .Verbosity (log .Lvl (ctx .GlobalInt (verbosityFlag .Name )))
130- glogger .Vmodule (ctx .GlobalString (vmoduleFlag .Name ))
131- glogger .BacktraceAt (ctx .GlobalString (backtraceAtFlag .Name ))
180+ verbosity := ctx .GlobalInt (verbosityFlag .Name )
181+ glogger .Verbosity (log .Lvl (verbosity ))
182+ vmodule := ctx .GlobalString (vmoduleFlag .Name )
183+ glogger .Vmodule (vmodule )
184+
185+ debug := ctx .GlobalBool (debugFlag .Name )
186+ if ctx .GlobalIsSet (legacyDebugFlag .Name ) {
187+ debug = ctx .GlobalBool (legacyDebugFlag .Name )
188+ log .Warn ("The flag --debug is deprecated and will be removed in the future, please use --log.debug" )
189+ }
190+ if ctx .GlobalIsSet (debugFlag .Name ) {
191+ debug = ctx .GlobalBool (debugFlag .Name )
192+ }
193+ log .PrintOrigins (debug )
194+
195+ backtrace := ctx .GlobalString (backtraceAtFlag .Name )
196+ if b := ctx .GlobalString (legacyBacktraceAtFlag .Name ); b != "" {
197+ backtrace = b
198+ log .Warn ("The flag --backtrace is deprecated and will be removed in the future, please use --log.backtrace" )
199+ }
200+ if b := ctx .GlobalString (backtraceAtFlag .Name ); b != "" {
201+ backtrace = b
202+ }
203+ glogger .BacktraceAt (backtrace )
204+
132205 log .Root ().SetHandler (glogger )
133206
134207 // profiling, tracing
135- runtime .MemProfileRate = ctx .GlobalInt (memprofilerateFlag .Name )
208+ runtime .MemProfileRate = memprofilerateFlag .Value
209+ if ctx .GlobalIsSet (legacyMemprofilerateFlag .Name ) {
210+ runtime .MemProfileRate = ctx .GlobalInt (legacyMemprofilerateFlag .Name )
211+ log .Warn ("The flag --memprofilerate is deprecated and will be removed in the future, please use --pprof.memprofilerate" )
212+ }
213+ if ctx .GlobalIsSet (memprofilerateFlag .Name ) {
214+ runtime .MemProfileRate = ctx .GlobalInt (memprofilerateFlag .Name )
215+ }
136216
137- Handler .SetBlockProfileRate (ctx .GlobalInt (blockprofilerateFlag .Name ))
217+ blockProfileRate := blockprofilerateFlag .Value
218+ if ctx .GlobalIsSet (legacyBlockprofilerateFlag .Name ) {
219+ blockProfileRate = ctx .GlobalInt (legacyBlockprofilerateFlag .Name )
220+ log .Warn ("The flag --blockprofilerate is deprecated and will be removed in the future, please use --pprof.blockprofilerate" )
221+ }
222+ if ctx .GlobalIsSet (blockprofilerateFlag .Name ) {
223+ blockProfileRate = ctx .GlobalInt (blockprofilerateFlag .Name )
224+ }
225+ Handler .SetBlockProfileRate (blockProfileRate )
138226
139227 if traceFile := ctx .GlobalString (traceFlag .Name ); traceFile != "" {
140228 if err := Handler .StartGoTrace (traceFile ); err != nil {
0 commit comments