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

Commit d603b54

Browse files
committed
problem: update logging to better manage severity, verbosity, and use display
solution: makes quite a few log lines better aware of verbosity and severity, so errors use .Error, more important logs have verbosities Warn, etc. add glog.D log lines for configuration notices, cmd progress reports, and other important HUD events
1 parent c2280ec commit d603b54

21 files changed

+262
-185
lines changed

accounts/watch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (w *watcher) loop() {
6868

6969
err := notify.Watch(w.ac.getKeydir(), w.ev, notify.All)
7070
if err != nil {
71-
glog.V(logger.Detail).Infof("can't watch %s: %v", w.ac.getKeydir(), err)
71+
glog.V(logger.Warn).Errorf("can't watch %s: %v", w.ac.getKeydir(), err)
7272
return
7373
}
7474
defer notify.Stop(w.ev)

cmd/geth/accountcmd.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func accountIndex(ctx *cli.Context) error {
204204
if len(errs) > 0 {
205205
for _, e := range errs {
206206
if e != nil {
207-
glog.V(logger.Error).Infof("init cache db err: %v", e)
207+
glog.V(logger.Error).Errorf("init cache db err: %v", e)
208208
}
209209
}
210210
}
@@ -236,10 +236,12 @@ func unlockAccount(ctx *cli.Context, accman *accounts.Manager, address string, i
236236
err = accman.Unlock(account, password)
237237
if err == nil {
238238
glog.V(logger.Info).Infof("Unlocked account %x", account.Address)
239+
glog.D(logger.Error).Infof("Unlocked account %x", account.Address)
239240
return account, password
240241
}
241242
if err, ok := err.(*accounts.AmbiguousAddrError); ok {
242243
glog.V(logger.Info).Infof("Unlocked account %x", account.Address)
244+
glog.D(logger.Error).Infof("Unlocked account %x", account.Address)
243245
return ambiguousAddrRecovery(accman, err, password), password
244246
}
245247
if err != accounts.ErrDecrypt {

cmd/geth/cmd.go

Lines changed: 46 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ func StartNode(stack *node.Node) {
8282
signal.Notify(sigc, os.Interrupt, syscall.SIGTERM)
8383
defer signal.Stop(sigc)
8484
sig := <-sigc
85-
glog.Infof("Got %v, shutting down...", sig)
85+
glog.V(logger.Warn).Warnf("Got %v, shutting down...", sig)
8686

8787
fails := make(chan error, 1)
8888
go func(fs chan error) {
8989
for {
9090
select {
9191
case e := <-fs:
9292
if e != nil {
93-
glog.V(logger.Error).Infof("node stop failure: %v", e)
93+
glog.V(logger.Error).Errorf("node stop failure: %v", e)
9494
}
9595
}
9696
}
@@ -127,7 +127,7 @@ func ImportChain(chain *core.BlockChain, fn string) error {
127127
defer close(interrupt)
128128
go func() {
129129
if _, ok := <-interrupt; ok {
130-
glog.Info("caught interrupt during import, will stop at next batch")
130+
glog.D(logger.Warn).Warnln("caught interrupt during import, will stop at next batch")
131131
}
132132
close(stop)
133133
}()
@@ -140,7 +140,7 @@ func ImportChain(chain *core.BlockChain, fn string) error {
140140
}
141141
}
142142

143-
glog.Infoln("Importing blockchain ", fn)
143+
glog.D(logger.Error).Infoln("Importing blockchain ", fn)
144144
fh, err := os.Open(fn)
145145
if err != nil {
146146
return err
@@ -180,7 +180,7 @@ func ImportChain(chain *core.BlockChain, fn string) error {
180180
return fmt.Errorf("interrupted")
181181
}
182182
if hasAllBlocks(chain, blocks[:i]) {
183-
glog.Infof("skipping batch %d, all blocks present [%x / %x]",
183+
glog.D(logger.Warn).Warnf("skipping batch %d, all blocks present [%x / %x]",
184184
batch, blocks[0].Hash().Bytes()[:4], blocks[i-1].Hash().Bytes()[:4])
185185
continue
186186
}
@@ -202,7 +202,7 @@ func hasAllBlocks(chain *core.BlockChain, bs []*types.Block) bool {
202202
}
203203

204204
func ExportChain(blockchain *core.BlockChain, fn string) error {
205-
glog.Infoln("Exporting blockchain to ", fn)
205+
glog.D(logger.Warn).Infoln("Exporting blockchain to ", fn)
206206
fh, err := os.OpenFile(fn, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.ModePerm)
207207
if err != nil {
208208
return err
@@ -211,12 +211,12 @@ func ExportChain(blockchain *core.BlockChain, fn string) error {
211211
if err := blockchain.Export(fh); err != nil {
212212
return err
213213
}
214-
glog.Infoln("Exported blockchain to ", fn)
214+
glog.D(logger.Error).Infoln("Exported blockchain to ", fn)
215215
return nil
216216
}
217217

218218
func ExportAppendChain(blockchain *core.BlockChain, fn string, first uint64, last uint64) error {
219-
glog.Infoln("Exporting blockchain to ", fn)
219+
glog.D(logger.Warn).Infoln("Exporting blockchain to ", fn)
220220
// TODO verify mode perms
221221
fh, err := os.OpenFile(fn, os.O_CREATE|os.O_APPEND|os.O_WRONLY, os.ModePerm)
222222
if err != nil {
@@ -226,40 +226,32 @@ func ExportAppendChain(blockchain *core.BlockChain, fn string, first uint64, las
226226
if err := blockchain.ExportN(fh, first, last); err != nil {
227227
return err
228228
}
229-
glog.Infoln("Exported blockchain to ", fn)
229+
glog.D(logger.Error).Infoln("Exported blockchain to ", fn)
230230
return nil
231231
}
232232

233233
func withLineBreak(s string) string {
234234
return s + "\n"
235235
}
236236

237-
func colorGreen(s interface{}) string {
238-
return fmt.Sprintf("\x1b[32m%v\x1b[39m", s)
239-
}
240-
241-
func colorBlue(s interface{}) string {
242-
return fmt.Sprintf("\x1b[36m%v\x1b[39m", s)
243-
}
244-
245237
func formatStatusKeyValue(prefix string, ss ...interface{}) (s string) {
246238

247239
s = ""
248240
// Single arg; category? ie Forks?
249241
if len(ss) == 1 {
250-
s += colorBlue(ss[0])
242+
s += logger.ColorBlue(fmt.Sprintf("%v", ss[0]))
251243
}
252244
if len(ss) == 2 {
253245
if ss[0] == "" {
254-
s += fmt.Sprintf("%v", colorGreen(ss[1]))
246+
s += fmt.Sprintf("%v", logger.ColorGreen(fmt.Sprintf("%v", ss[1])))
255247
} else {
256-
s += fmt.Sprintf("%v: %v", ss[0], colorGreen(ss[1]))
248+
s += fmt.Sprintf("%v: %v", ss[0], logger.ColorGreen(fmt.Sprintf("%v", ss[1])))
257249
}
258250
}
259251
if len(ss) > 2 {
260252
s += fmt.Sprintf("%v:", ss[0])
261253
for i := 2; i < len(ss); i++ {
262-
s += withLineBreak(fmt.Sprintf(" %v", colorGreen(ss[i])))
254+
s += withLineBreak(fmt.Sprintf(" %v", logger.ColorGreen(fmt.Sprintf("%v", ss[i]))))
263255
}
264256
}
265257

@@ -529,16 +521,16 @@ func status(ctx *cli.Context) error {
529521
for _, p := range printme {
530522
s += withLineBreak(sep)
531523
// right align category title
532-
s += withLineBreak(strings.Repeat(" ", len(sep)-len(p.title)) + colorBlue(p.title))
524+
s += withLineBreak(strings.Repeat(" ", len(sep)-len(p.title)) + logger.ColorBlue(p.title))
533525
for _, v := range p.keyVals {
534526
s += v
535527
}
536528
}
537-
glog.V(logger.Info).Info(s)
529+
glog.D(logger.Info).Infoln(s)
538530

539531
// Return here if database has not been initialized.
540532
if !shouldUseExisting {
541-
glog.V(logger.Info).Info("Geth has not been initialized; no database information available yet.")
533+
glog.D(logger.Info).Infoln("Geth has not been initialized; no database information available yet.")
542534
return nil
543535
}
544536

@@ -547,11 +539,11 @@ func status(ctx *cli.Context) error {
547539
s = "\n"
548540
s += withLineBreak(sep)
549541
title := "Chain database status"
550-
s += withLineBreak(strings.Repeat(" ", len(sep)-len(title)) + colorBlue(title))
542+
s += withLineBreak(strings.Repeat(" ", len(sep)-len(title)) + logger.ColorBlue(title))
551543
for _, v := range formatChainDataPretty(datadir, chaindata) {
552544
s += v
553545
}
554-
glog.V(logger.Info).Info(s)
546+
glog.D(logger.Info).Infoln(s)
555547

556548
return nil
557549
}
@@ -572,10 +564,10 @@ func rollback(ctx *cli.Context) error {
572564
bc, chainDB := MakeChain(ctx)
573565
defer chainDB.Close()
574566

575-
glog.Warning("Rolling back blockchain...")
567+
glog.D(logger.Warn).Infoln("Rolling back blockchain...")
576568

577569
if err := bc.SetHead(blockIndex); err != nil {
578-
glog.V(logger.Warn).Infof("error setting head: %v", err)
570+
glog.D(logger.Error).Errorf("error setting head: %v", err)
579571
}
580572

581573
// Check if *neither* block nor fastblock numbers match desired head number
@@ -584,7 +576,7 @@ func rollback(ctx *cli.Context) error {
584576
if nowCurrentHead != blockIndex && nowCurrentFastHead != blockIndex {
585577
glog.Fatalf("ERROR: Wanted rollback to set head to: %v, instead current head is: %v", blockIndex, nowCurrentHead)
586578
}
587-
glog.Infof("SUCCESS: Head block set to: %v", nowCurrentHead)
579+
glog.D(logger.Error).Infof("Success. Head block set to: %v", nowCurrentHead)
588580
return nil
589581
}
590582

@@ -598,7 +590,7 @@ func dumpChainConfig(ctx *cli.Context) error {
598590
glog.Fatal("Dump config should only be used with default chain configurations (mainnet or morden).")
599591
}
600592

601-
glog.V(logger.Info).Infof("Dumping configuration for: %v", chainIdentity)
593+
glog.D(logger.Warn).Infof("Dumping configuration for: %v", chainIdentity)
602594

603595
chainConfigFilePath := ctx.Args().First()
604596
chainConfigFilePath = filepath.Clean(chainConfigFilePath)
@@ -618,7 +610,7 @@ func dumpChainConfig(ctx *cli.Context) error {
618610
}
619611
di, _ = os.Stat(fb) // update var with new dir info
620612
} else {
621-
glog.V(logger.Error).Infof("err: %v (at '%v')", de, fb)
613+
glog.V(logger.Error).Errorf("err: %v (at '%v')", de, fb)
622614
}
623615
}
624616
if !di.IsDir() {
@@ -658,7 +650,7 @@ func dumpChainConfig(ctx *cli.Context) error {
658650
return writeError
659651
}
660652

661-
glog.V(logger.Info).Info(fmt.Sprintf("Wrote chain config file to \x1b[32m%s\x1b[39m.", chainConfigFilePath))
653+
glog.D(logger.Error).Infoln(fmt.Sprintf("Wrote chain config file to \x1b[32m%s\x1b[39m.", chainConfigFilePath))
662654
return nil
663655
}
664656

@@ -706,6 +698,7 @@ func makedag(ctx *cli.Context) error {
706698
glog.Fatal("Can't find dir")
707699
}
708700
glog.V(logger.Info).Infoln("making DAG, this could take awhile...")
701+
glog.D(logger.Warn).Infoln("making DAG, this could take awhile...")
709702
ethash.MakeDAG(blockNum, dir)
710703
}
711704
default:
@@ -1207,7 +1200,7 @@ func recoverChaindata(ctx *cli.Context) error {
12071200
if !ctx.GlobalBool(aliasableName(FakePoWFlag.Name, ctx)) {
12081201
pow = ethash.New()
12091202
} else {
1210-
glog.V(logger.Info).Info("Consensus: fake")
1203+
glog.V(logger.Warn).Info("Consensus: fake")
12111204
}
12121205

12131206
bc, err := core.NewBlockChainDryrun(bcdb, sconf.ChainConfig, pow, new(event.TypeMux))
@@ -1216,42 +1209,42 @@ func recoverChaindata(ctx *cli.Context) error {
12161209
}
12171210

12181211
if blockchainLoadError := bc.LoadLastState(true); blockchainLoadError != nil {
1219-
glog.V(logger.Error).Infof("! Found error while loading blockchain: %v", blockchainLoadError)
1212+
glog.V(logger.Error).Errorf("Error while loading blockchain: %v", blockchainLoadError)
12201213
// but do not return
12211214
}
12221215

12231216
header := bc.CurrentHeader()
12241217
currentBlock := bc.CurrentBlock()
12251218
currentFastBlock := bc.CurrentFastBlock()
12261219

1227-
glog.V(logger.Error).Infoln("Current status (before recovery attempt):")
1220+
glog.D(logger.Error).Infoln("Current status (before recovery attempt):")
12281221
if header != nil {
1229-
glog.V(logger.Error).Infof("Last header: #%d\n", header.Number.Uint64())
1222+
glog.D(logger.Error).Infof("Last header: #%d\n", header.Number.Uint64())
12301223
if currentBlock != nil {
1231-
glog.V(logger.Error).Infof("Last block: #%d\n", currentBlock.Number())
1224+
glog.D(logger.Error).Infof("Last block: #%d\n", currentBlock.Number())
12321225
} else {
1233-
glog.V(logger.Error).Infoln("! Last block: nil")
1226+
glog.D(logger.Error).Errorf("! Last block: nil")
12341227
}
12351228
if currentFastBlock != nil {
1236-
glog.V(logger.Error).Infof("Last fast block: #%d\n", currentFastBlock.Number())
1229+
glog.D(logger.Error).Infof("Last fast block: #%d\n", currentFastBlock.Number())
12371230
} else {
1238-
glog.V(logger.Error).Infoln("! Last fast block: nil")
1231+
glog.D(logger.Error).Errorln("! Last fast block: nil")
12391232
}
12401233
} else {
1241-
glog.V(logger.Error).Infoln("! Last header: nil")
1234+
glog.D(logger.Error).Errorln("! Last header: nil")
12421235
}
12431236

1244-
glog.V(logger.Error).Infoln(glog.Separator("-"))
1237+
glog.D(logger.Error).Infoln(glog.Separator("-"))
12451238

1246-
glog.V(logger.Error).Infoln("Checking db validity and recoverable data...")
1239+
glog.D(logger.Error).Infoln("Checking db validity and recoverable data...")
12471240
checkpoint := bc.Recovery(1, 2048)
1248-
glog.V(logger.Error).Infof("Found last recoverable checkpoint=#%d\n", checkpoint)
1241+
glog.D(logger.Error).Infof("Found last recoverable checkpoint=#%d\n", checkpoint)
12491242

1250-
glog.V(logger.Error).Infoln(glog.Separator("-"))
1243+
glog.D(logger.Error).Infoln(glog.Separator("-"))
12511244

1252-
glog.V(logger.Error).Infoln("Setting blockchain db head to last safe checkpoint...")
1245+
glog.D(logger.Error).Infoln("Setting blockchain db head to last safe checkpoint...")
12531246
if setHeadErr := bc.SetHead(checkpoint); setHeadErr != nil {
1254-
glog.V(logger.Error).Infof("Error setting head: %v\n", setHeadErr)
1247+
glog.D(logger.Error).Errorf("Error setting head: %v\n", setHeadErr)
12551248
return setHeadErr
12561249
}
12571250
return nil
@@ -1268,7 +1261,7 @@ func askForConfirmation(s string) bool {
12681261
reader := bufio.NewReader(os.Stdin)
12691262

12701263
for {
1271-
glog.V(logger.Error).Infof("%s [y/n]: ", s)
1264+
glog.D(logger.Error).Warnf("%s [y/n]: ", s)
12721265

12731266
response, err := reader.ReadString('\n')
12741267
if err != nil {
@@ -1282,9 +1275,9 @@ func askForConfirmation(s string) bool {
12821275
} else if response == "n" || response == "no" {
12831276
return false
12841277
} else {
1285-
glog.V(logger.Error).Infoln(glog.Separator("*"))
1286-
glog.V(logger.Error).Infoln("* INVALID RESPONSE: Please respond with [y|yes] or [n|no], or use CTRL-C to abort.")
1287-
glog.V(logger.Error).Infoln(glog.Separator("*"))
1278+
glog.D(logger.Error).Warnln(glog.Separator("*"))
1279+
glog.D(logger.Error).Errorln("* INVALID RESPONSE: Please respond with [y|yes] or [n|no], or use CTRL-C to abort.")
1280+
glog.D(logger.Error).Warnln(glog.Separator("*"))
12881281
}
12891282
}
12901283
}
@@ -1300,9 +1293,9 @@ func resetChaindata(ctx *cli.Context) error {
13001293
if err := os.RemoveAll(dir); err != nil {
13011294
return err
13021295
}
1303-
glog.V(logger.Error).Infof("Successfully removed chaindata directory: '%s'\n", dir)
1296+
glog.D(logger.Error).Infof("Successfully removed chaindata directory: '%s'\n", dir)
13041297
} else {
1305-
glog.V(logger.Error).Infoln("Leaving chaindata untouched. As you were.")
1298+
glog.D(logger.Error).Infoln("Leaving chaindata untouched. As you were.")
13061299
}
13071300
return nil
13081301
}

0 commit comments

Comments
 (0)