Skip to content

Commit 0b38f55

Browse files
authored
make logs colorful, mainly cyan (#379)
1 parent 9ce7a3b commit 0b38f55

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

pkg/logger/logger.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func (l *Logger) LogDataStatus(ctx context.Context, status *results.CheckDataSta
168168
}
169169

170170
l.lastStatsMessage = statsMessage
171-
l.zapLogger.Info(statsMessage)
171+
color.Cyan(statsMessage)
172172

173173
// If Progress is nil, it means we're already done.
174174
if status.Progress == nil {
@@ -194,7 +194,7 @@ func (l *Logger) LogDataStatus(ctx context.Context, status *results.CheckDataSta
194194
}
195195

196196
l.lastProgressMessage = progressMessage
197-
l.zapLogger.Info(progressMessage)
197+
color.Cyan(progressMessage)
198198
}
199199

200200
// LogConstructionStatus logs results.CheckConstructionStatus.
@@ -218,7 +218,7 @@ func (l *Logger) LogConstructionStatus(
218218
statsMessage = AddRequestUUID(statsMessage, l.logRequestUUID)
219219

220220
l.lastStatsMessage = statsMessage
221-
l.zapLogger.Info(statsMessage)
221+
color.Cyan(statsMessage)
222222
}
223223

224224
// LogMemoryStats logs memory usage information.
@@ -252,7 +252,7 @@ func (l *Logger) AddBlockStream(
252252
)
253253
if err != nil {
254254
err = fmt.Errorf("failed to open file %s: %w", path.Join(l.logDir, blockStreamFile), err)
255-
l.zapLogger.Error(err.Error())
255+
color.Red(err.Error())
256256
return err
257257
}
258258

@@ -267,7 +267,7 @@ func (l *Logger) AddBlockStream(
267267
block.ParentBlockIdentifier.Hash,
268268
)
269269
blockString = AddRequestUUID(blockString, l.logRequestUUID)
270-
l.zapLogger.Info(blockString)
270+
color.Cyan(blockString)
271271
if _, err := f.WriteString(blockString); err != nil {
272272
return fmt.Errorf("failed to write block string %s: %w", blockString, err)
273273
}
@@ -292,7 +292,7 @@ func (l *Logger) RemoveBlockStream(
292292
)
293293
if err != nil {
294294
err = fmt.Errorf("failed to open file %s: %w", path.Join(l.logDir, blockStreamFile), err)
295-
l.zapLogger.Error(err.Error())
295+
color.Red(err.Error())
296296
return err
297297
}
298298

@@ -305,11 +305,11 @@ func (l *Logger) RemoveBlockStream(
305305
block.Hash,
306306
)
307307
blockString = AddRequestUUID(blockString, l.logRequestUUID)
308-
l.zapLogger.Info(blockString)
308+
color.Cyan(blockString)
309309
_, err = f.WriteString(blockString)
310310
if err != nil {
311311
err = fmt.Errorf("failed to write block string %s: %w", blockString, err)
312-
l.zapLogger.Error(err.Error())
312+
color.Red(err.Error())
313313
return err
314314
}
315315

@@ -333,7 +333,7 @@ func (l *Logger) TransactionStream(
333333
)
334334
if err != nil {
335335
err = fmt.Errorf("failed to open file %s: %w", path.Join(l.logDir, transactionStreamFile), err)
336-
l.zapLogger.Error(err.Error())
336+
color.Red(err.Error())
337337
return err
338338
}
339339

@@ -347,11 +347,11 @@ func (l *Logger) TransactionStream(
347347
block.BlockIdentifier.Hash,
348348
)
349349
transactionString = AddRequestUUID(transactionString, l.logRequestUUID)
350-
l.zapLogger.Info(transactionString)
350+
color.Cyan(transactionString)
351351
_, err = f.WriteString(transactionString)
352352
if err != nil {
353353
err = fmt.Errorf("failed to write transaction string %s: %w", transactionString, err)
354-
l.zapLogger.Error(err.Error())
354+
color.Red(err.Error())
355355
return err
356356
}
357357

@@ -383,11 +383,11 @@ func (l *Logger) TransactionStream(
383383
*op.Status,
384384
)
385385
transactionOperationString = AddRequestUUID(transactionOperationString, l.logRequestUUID)
386-
l.zapLogger.Info(transactionOperationString)
386+
color.Cyan(transactionOperationString)
387387
_, err = f.WriteString(transactionOperationString)
388388
if err != nil {
389389
err = fmt.Errorf("failed to write transaction operation string %s: %w", transactionOperationString, err)
390-
l.zapLogger.Error(err.Error())
390+
color.Red(err.Error())
391391
return err
392392
}
393393
}
@@ -413,7 +413,7 @@ func (l *Logger) BalanceStream(
413413
)
414414
if err != nil {
415415
err = fmt.Errorf("failed to open file %s: %w", path.Join(l.logDir, balanceStreamFile), err)
416-
l.zapLogger.Error(err.Error())
416+
color.Red(err.Error())
417417
return err
418418
}
419419

@@ -429,10 +429,10 @@ func (l *Logger) BalanceStream(
429429
balanceChange.Block.Hash,
430430
)
431431
balanceLog = AddRequestUUID(balanceLog, l.logRequestUUID)
432-
l.zapLogger.Info(balanceLog)
432+
color.Cyan(balanceLog)
433433
if _, err := f.WriteString(fmt.Sprintf("%s\n", balanceLog)); err != nil {
434434
err = fmt.Errorf("failed to write balance log %s: %w", balanceLog, err)
435-
l.zapLogger.Error(err.Error())
435+
color.Red(err.Error())
436436
return err
437437
}
438438
}
@@ -460,7 +460,7 @@ func (l *Logger) ReconcileSuccessStream(
460460
)
461461
if err != nil {
462462
err = fmt.Errorf("failed to open file %s: %w", path.Join(l.logDir, reconcileSuccessStreamFile), err)
463-
l.zapLogger.Error(err.Error())
463+
color.Red(err.Error())
464464
return err
465465
}
466466

@@ -473,7 +473,7 @@ func (l *Logger) ReconcileSuccessStream(
473473
block.Index,
474474
)
475475
reconciledLog = AddRequestUUID(reconciledLog, l.logRequestUUID)
476-
l.zapLogger.Info(reconciledLog)
476+
color.Cyan(reconciledLog)
477477

478478
reconciliationSuccessString := fmt.Sprintf(
479479
"Type:%s Account: %s Currency: %s Balance: %s Block: %d:%s",
@@ -485,12 +485,12 @@ func (l *Logger) ReconcileSuccessStream(
485485
block.Hash,
486486
)
487487
reconciliationSuccessString = AddRequestUUID(reconciliationSuccessString, l.logRequestUUID)
488-
l.zapLogger.Info(reconciliationSuccessString)
488+
color.Cyan(reconciliationSuccessString)
489489

490490
_, err = f.WriteString(reconciliationSuccessString)
491491
if err != nil {
492492
err = fmt.Errorf("failed to write reconciliation success string %s: %w", reconciliationSuccessString, err)
493-
l.zapLogger.Error(err.Error())
493+
color.Red(err.Error())
494494
return err
495495
}
496496

@@ -541,7 +541,7 @@ func (l *Logger) ReconcileFailureStream(
541541
)
542542
if err != nil {
543543
err = fmt.Errorf("failed to open file %s: %w", path.Join(l.logDir, reconcileFailureStreamFile), err)
544-
l.zapLogger.Error(err.Error())
544+
color.Red(err.Error())
545545
return err
546546
}
547547

@@ -558,11 +558,11 @@ func (l *Logger) ReconcileFailureStream(
558558
liveBalance,
559559
)
560560
reconciliationFailureString = AddRequestUUID(reconciliationFailureString, l.logRequestUUID)
561-
l.zapLogger.Info(reconciliationFailureString)
561+
color.Cyan(reconciliationFailureString)
562562
_, err = f.WriteString(reconciliationFailureString)
563563
if err != nil {
564564
err = fmt.Errorf("failed to write reconciliation failure string %s: %w", reconciliationFailureString, err)
565-
l.zapLogger.Error(err.Error())
565+
color.Red(err.Error())
566566
return err
567567
}
568568

@@ -622,15 +622,15 @@ func LogTransactionCreated(
622622
func AddRequestUUIDFromContext(ctx context.Context, msg string) string {
623623
requestUUID := requestUUIDFromContext(ctx)
624624
if requestUUID != "" {
625-
msg = fmt.Sprintf("%s, RequestUUID: %s", msg, requestUUID)
625+
msg = fmt.Sprintf("%s, RequestID: %s", msg, requestUUID)
626626
}
627627
return msg
628628
}
629629

630630
// Add requestUUID to the tip
631631
func AddRequestUUID(msg string, requestUUID string) string {
632632
if requestUUID != "" {
633-
msg = fmt.Sprintf("%s, RequestUUID: %s", msg, requestUUID)
633+
msg = fmt.Sprintf("%s, RequestID: %s", msg, requestUUID)
634634
}
635635
return msg
636636
}

0 commit comments

Comments
 (0)