Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make logs colorful mainly cyan #379

Merged
merged 1 commit into from
Dec 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (l *Logger) LogDataStatus(ctx context.Context, status *results.CheckDataSta
}

l.lastStatsMessage = statsMessage
l.zapLogger.Info(statsMessage)
color.Cyan(statsMessage)

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

l.lastProgressMessage = progressMessage
l.zapLogger.Info(progressMessage)
color.Cyan(progressMessage)
}

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

l.lastStatsMessage = statsMessage
l.zapLogger.Info(statsMessage)
color.Cyan(statsMessage)
}

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

Expand All @@ -267,7 +267,7 @@ func (l *Logger) AddBlockStream(
block.ParentBlockIdentifier.Hash,
)
blockString = AddRequestUUID(blockString, l.logRequestUUID)
l.zapLogger.Info(blockString)
color.Cyan(blockString)
if _, err := f.WriteString(blockString); err != nil {
return fmt.Errorf("failed to write block string %s: %w", blockString, err)
}
Expand All @@ -292,7 +292,7 @@ func (l *Logger) RemoveBlockStream(
)
if err != nil {
err = fmt.Errorf("failed to open file %s: %w", path.Join(l.logDir, blockStreamFile), err)
l.zapLogger.Error(err.Error())
color.Red(err.Error())
return err
}

Expand All @@ -305,11 +305,11 @@ func (l *Logger) RemoveBlockStream(
block.Hash,
)
blockString = AddRequestUUID(blockString, l.logRequestUUID)
l.zapLogger.Info(blockString)
color.Cyan(blockString)
_, err = f.WriteString(blockString)
if err != nil {
err = fmt.Errorf("failed to write block string %s: %w", blockString, err)
l.zapLogger.Error(err.Error())
color.Red(err.Error())
return err
}

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

Expand All @@ -347,11 +347,11 @@ func (l *Logger) TransactionStream(
block.BlockIdentifier.Hash,
)
transactionString = AddRequestUUID(transactionString, l.logRequestUUID)
l.zapLogger.Info(transactionString)
color.Cyan(transactionString)
_, err = f.WriteString(transactionString)
if err != nil {
err = fmt.Errorf("failed to write transaction string %s: %w", transactionString, err)
l.zapLogger.Error(err.Error())
color.Red(err.Error())
return err
}

Expand Down Expand Up @@ -383,11 +383,11 @@ func (l *Logger) TransactionStream(
*op.Status,
)
transactionOperationString = AddRequestUUID(transactionOperationString, l.logRequestUUID)
l.zapLogger.Info(transactionOperationString)
color.Cyan(transactionOperationString)
_, err = f.WriteString(transactionOperationString)
if err != nil {
err = fmt.Errorf("failed to write transaction operation string %s: %w", transactionOperationString, err)
l.zapLogger.Error(err.Error())
color.Red(err.Error())
return err
}
}
Expand All @@ -413,7 +413,7 @@ func (l *Logger) BalanceStream(
)
if err != nil {
err = fmt.Errorf("failed to open file %s: %w", path.Join(l.logDir, balanceStreamFile), err)
l.zapLogger.Error(err.Error())
color.Red(err.Error())
return err
}

Expand All @@ -429,10 +429,10 @@ func (l *Logger) BalanceStream(
balanceChange.Block.Hash,
)
balanceLog = AddRequestUUID(balanceLog, l.logRequestUUID)
l.zapLogger.Info(balanceLog)
color.Cyan(balanceLog)
if _, err := f.WriteString(fmt.Sprintf("%s\n", balanceLog)); err != nil {
err = fmt.Errorf("failed to write balance log %s: %w", balanceLog, err)
l.zapLogger.Error(err.Error())
color.Red(err.Error())
return err
}
}
Expand Down Expand Up @@ -460,7 +460,7 @@ func (l *Logger) ReconcileSuccessStream(
)
if err != nil {
err = fmt.Errorf("failed to open file %s: %w", path.Join(l.logDir, reconcileSuccessStreamFile), err)
l.zapLogger.Error(err.Error())
color.Red(err.Error())
return err
}

Expand All @@ -473,7 +473,7 @@ func (l *Logger) ReconcileSuccessStream(
block.Index,
)
reconciledLog = AddRequestUUID(reconciledLog, l.logRequestUUID)
l.zapLogger.Info(reconciledLog)
color.Cyan(reconciledLog)

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

_, err = f.WriteString(reconciliationSuccessString)
if err != nil {
err = fmt.Errorf("failed to write reconciliation success string %s: %w", reconciliationSuccessString, err)
l.zapLogger.Error(err.Error())
color.Red(err.Error())
return err
}

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

Expand All @@ -558,11 +558,11 @@ func (l *Logger) ReconcileFailureStream(
liveBalance,
)
reconciliationFailureString = AddRequestUUID(reconciliationFailureString, l.logRequestUUID)
l.zapLogger.Info(reconciliationFailureString)
color.Cyan(reconciliationFailureString)
_, err = f.WriteString(reconciliationFailureString)
if err != nil {
err = fmt.Errorf("failed to write reconciliation failure string %s: %w", reconciliationFailureString, err)
l.zapLogger.Error(err.Error())
color.Red(err.Error())
return err
}

Expand Down Expand Up @@ -622,15 +622,15 @@ func LogTransactionCreated(
func AddRequestUUIDFromContext(ctx context.Context, msg string) string {
requestUUID := requestUUIDFromContext(ctx)
if requestUUID != "" {
msg = fmt.Sprintf("%s, RequestUUID: %s", msg, requestUUID)
msg = fmt.Sprintf("%s, RequestID: %s", msg, requestUUID)
}
return msg
}

// Add requestUUID to the tip
func AddRequestUUID(msg string, requestUUID string) string {
if requestUUID != "" {
msg = fmt.Sprintf("%s, RequestUUID: %s", msg, requestUUID)
msg = fmt.Sprintf("%s, RequestID: %s", msg, requestUUID)
}
return msg
}
Expand Down