From eab50ad97e5c94f5c7e0c03b4b8f9f8d1222a795 Mon Sep 17 00:00:00 2001 From: Fred Carle Date: Wed, 13 Jul 2022 19:52:33 -0400 Subject: [PATCH] remove extra log levels --- logging/logger.go | 21 ---------------- logging/logging.go | 10 +++----- logging/logging_test.go | 50 +++++++++++--------------------------- net/peer.go | 6 ++--- tests/integration/utils.go | 6 ++--- 5 files changed, 23 insertions(+), 70 deletions(-) diff --git a/logging/logger.go b/logging/logger.go index ec45127bfa..926fc46c10 100644 --- a/logging/logger.go +++ b/logging/logger.go @@ -55,13 +55,6 @@ func (l *logger) Info(ctx context.Context, message string, keyvals ...KV) { l.logger.Info(message, toZapFields(keyvals)...) } -func (l *logger) Warn(ctx context.Context, message string, keyvals ...KV) { - l.syncLock.RLock() - defer l.syncLock.RUnlock() - - l.logger.Warn(message, toZapFields(keyvals)...) -} - func (l *logger) Error(ctx context.Context, message string, keyvals ...KV) { l.syncLock.RLock() defer l.syncLock.RUnlock() @@ -96,13 +89,6 @@ func (l *logger) FatalE(ctx context.Context, message string, err error, keyvals l.logger.Fatal(message, toZapFields(kvs)...) } -func (l *logger) FeedbackDebug(ctx context.Context, message string, keyvals ...KV) { - l.Debug(ctx, message, keyvals...) - if l.consoleLogger != nil { - l.consoleLogger.Println(message) - } -} - func (l *logger) FeedbackInfo(ctx context.Context, message string, keyvals ...KV) { l.Info(ctx, message, keyvals...) if l.consoleLogger != nil { @@ -110,13 +96,6 @@ func (l *logger) FeedbackInfo(ctx context.Context, message string, keyvals ...KV } } -func (l *logger) FeedbackWarn(ctx context.Context, message string, keyvals ...KV) { - l.Warn(ctx, message, keyvals...) - if l.consoleLogger != nil { - l.consoleLogger.Println(message) - } -} - func (l *logger) FeedbackError(ctx context.Context, message string, keyvals ...KV) { l.Error(ctx, message, keyvals...) if l.consoleLogger != nil { diff --git a/logging/logging.go b/logging/logging.go index 8a2fd4f4f4..c29b924756 100644 --- a/logging/logging.go +++ b/logging/logging.go @@ -35,8 +35,6 @@ type Logger interface { Debug(ctx context.Context, message string, keyvals ...KV) // Info logs a message at info log level. Key-value pairs can be added. Info(ctx context.Context, message string, keyvals ...KV) - // Warn logs a message at warn log level. Key-value pairs can be added. - Warn(ctx context.Context, message string, keyvals ...KV) // Error logs a message at error log level. Key-value pairs can be added. Error(ctx context.Context, message string, keyvals ...KV) // ErrorErr logs a message and an error at error log level. Key-value pairs can be added. @@ -45,12 +43,11 @@ type Logger interface { Fatal(ctx context.Context, message string, keyvals ...KV) // FatalE logs a message and an error at fatal log level. Key-value pairs can be added. FatalE(ctx context.Context, message string, err error, keyvals ...KV) - // FeedbackDebug calls Debug and sends the message to stderr if logs are sent to a file. - FeedbackDebug(ctx context.Context, message string, keyvals ...KV) + + // Feedback prefixed method ensure that messsages reach a user in case the logs are sent to a file. + // FeedbackInfo calls Info and sends the message to stderr if logs are sent to a file. FeedbackInfo(ctx context.Context, message string, keyvals ...KV) - // FeedbackWarn calls Warn and sends the message to stderr if logs are sent to a file. - FeedbackWarn(ctx context.Context, message string, keyvals ...KV) // FeedbackError calls Error and sends the message to stderr if logs are sent to a file. FeedbackError(ctx context.Context, message string, keyvals ...KV) // FeedbackErrorE calls ErrorE and sends the message to stderr if logs are sent to a file. @@ -59,6 +56,7 @@ type Logger interface { FeedbackFatal(ctx context.Context, message string, keyvals ...KV) // FeedbackFatalE calls FatalE and sends the message to stderr if logs are sent to a file. FeedbackFatalE(ctx context.Context, message string, err error, keyvals ...KV) + // Flush flushes any buffered log entries. Flush() error // ApplyConfig updates the logger with a new config. diff --git a/logging/logging_test.go b/logging/logging_test.go index be7abc1801..2fa8819025 100644 --- a/logging/logging_test.go +++ b/logging/logging_test.go @@ -200,7 +200,6 @@ type LogLevelTestCase struct { func logDebug(l Logger, c context.Context, m string) { l.Debug(c, m) } func logInfo(l Logger, c context.Context, m string) { l.Info(c, m) } -func logWarn(l Logger, c context.Context, m string) { l.Warn(c, m) } func logError(l Logger, c context.Context, m string) { l.Error(c, m) } func logErrorE(l Logger, c context.Context, m string) { l.ErrorE(c, m, fmt.Errorf("test error")) } @@ -209,7 +208,6 @@ func getLogLevelTestCase() []LogLevelTestCase { {Debug, logDebug, "DEBUG", false, false, true}, {Debug, logDebug, "DEBUG", false, false, false}, {Debug, logInfo, "INFO", false, false, false}, - {Debug, logWarn, "WARN", false, false, false}, {Debug, logError, "ERROR", false, false, false}, {Debug, logError, "ERROR", true, true, false}, {Debug, logErrorE, "ERROR", false, false, false}, @@ -217,22 +215,18 @@ func getLogLevelTestCase() []LogLevelTestCase { {Info, logDebug, "", false, false, false}, {Info, logInfo, "INFO", false, false, true}, {Info, logInfo, "INFO", false, false, false}, - {Info, logWarn, "WARN", false, false, false}, {Info, logError, "ERROR", false, false, false}, {Info, logError, "ERROR", true, true, false}, {Info, logErrorE, "ERROR", false, false, false}, {Info, logErrorE, "ERROR", true, true, false}, {Warn, logDebug, "", false, false, false}, {Warn, logInfo, "", false, false, false}, - {Warn, logWarn, "WARN", false, false, true}, - {Warn, logWarn, "WARN", false, false, false}, {Warn, logError, "ERROR", false, false, false}, {Warn, logError, "ERROR", true, true, false}, {Warn, logErrorE, "ERROR", false, false, false}, {Warn, logErrorE, "ERROR", true, true, false}, {Error, logDebug, "", false, false, false}, {Error, logInfo, "", false, false, false}, - {Error, logWarn, "", false, false, false}, {Error, logError, "ERROR", false, false, true}, {Error, logError, "ERROR", false, false, false}, {Error, logError, "ERROR", true, true, false}, @@ -241,7 +235,6 @@ func getLogLevelTestCase() []LogLevelTestCase { {Fatal, logDebug, "", false, false, true}, {Fatal, logDebug, "", false, false, false}, {Fatal, logInfo, "", false, false, false}, - {Fatal, logWarn, "", false, false, false}, {Fatal, logError, "", false, false, false}, {Fatal, logErrorE, "", false, false, false}, } @@ -528,9 +521,7 @@ func TestLogWritesMessagesToLogGivenUpdatedLogPath(t *testing.T) { } } -func logFeedbackDebug(l Logger, c context.Context, m string) { l.FeedbackDebug(c, m) } func logFeedbackInfo(l Logger, c context.Context, m string) { l.FeedbackInfo(c, m) } -func logFeedbackWarn(l Logger, c context.Context, m string) { l.FeedbackWarn(c, m) } func logFeedbackError(l Logger, c context.Context, m string) { l.FeedbackError(c, m) } func logFeedbackErrorE(l Logger, c context.Context, m string) { l.FeedbackErrorE(c, m, fmt.Errorf("test error")) @@ -538,42 +529,29 @@ func logFeedbackErrorE(l Logger, c context.Context, m string) { func getFeedbackLogLevelTestCase() []LogLevelTestCase { return []LogLevelTestCase{ - {Debug, logFeedbackDebug, "DEBUG", false, false, true}, - {Debug, logFeedbackDebug, "DEBUG", false, false, false}, {Debug, logFeedbackInfo, "INFO", false, false, false}, - {Debug, logFeedbackWarn, "WARN", false, false, false}, {Debug, logFeedbackError, "ERROR", false, false, false}, {Debug, logFeedbackError, "ERROR", true, true, false}, {Debug, logFeedbackErrorE, "ERROR", false, false, false}, {Debug, logFeedbackErrorE, "ERROR", true, true, false}, - {Info, logFeedbackDebug, "", false, false, false}, {Info, logFeedbackInfo, "INFO", false, false, true}, {Info, logFeedbackInfo, "INFO", false, false, false}, - {Info, logFeedbackWarn, "WARN", false, false, false}, {Info, logFeedbackError, "ERROR", false, false, false}, {Info, logFeedbackError, "ERROR", true, true, false}, {Info, logFeedbackErrorE, "ERROR", false, false, false}, {Info, logFeedbackErrorE, "ERROR", true, true, false}, - {Warn, logFeedbackDebug, "", false, false, false}, {Warn, logFeedbackInfo, "", false, false, false}, - {Warn, logFeedbackWarn, "WARN", false, false, true}, - {Warn, logFeedbackWarn, "WARN", false, false, false}, {Warn, logFeedbackError, "ERROR", false, false, false}, {Warn, logFeedbackError, "ERROR", true, true, false}, {Warn, logFeedbackErrorE, "ERROR", false, false, false}, {Warn, logFeedbackErrorE, "ERROR", true, true, false}, - {Error, logFeedbackDebug, "", false, false, false}, {Error, logFeedbackInfo, "", false, false, false}, - {Error, logFeedbackWarn, "", false, false, false}, {Error, logFeedbackError, "ERROR", false, false, true}, {Error, logFeedbackError, "ERROR", false, false, false}, {Error, logFeedbackError, "ERROR", true, true, false}, {Error, logFeedbackErrorE, "ERROR", false, false, false}, {Error, logFeedbackErrorE, "ERROR", true, true, false}, - {Fatal, logFeedbackDebug, "", false, false, true}, - {Fatal, logFeedbackDebug, "", false, false, false}, {Fatal, logFeedbackInfo, "", false, false, false}, - {Fatal, logFeedbackWarn, "", false, false, false}, {Fatal, logFeedbackError, "", false, false, false}, {Fatal, logFeedbackErrorE, "", false, false, false}, } @@ -634,7 +612,7 @@ func TestLogWritesMessagesToLogGivenPipeWithValidPath(t *testing.T) { }) logMessage := "test log message" - logger.Warn(ctx, logMessage) + logger.Info(ctx, logMessage) logger.Flush() logLines, err := getLogLines(t, logPath) @@ -647,7 +625,7 @@ func TestLogWritesMessagesToLogGivenPipeWithValidPath(t *testing.T) { } assert.Equal(t, logMessage, logLines[0]["msg"]) - assert.Equal(t, "WARN", logLines[0]["level"]) + assert.Equal(t, "INFO", logLines[0]["level"]) assert.Equal(t, "TestLogName", logLines[0]["logger"]) // caller is disabled by default assert.NotContains(t, logLines[0], "logging_test.go") @@ -665,7 +643,7 @@ func TestLogDoesNotWriteMessagesToLogGivenOverrideForAnotherLoggerReducingLogLev }) logMessage := "test log message" - logger.Warn(ctx, logMessage) + logger.Info(ctx, logMessage) logger.Flush() logLines, err := getLogLines(t, logPath) @@ -688,7 +666,7 @@ func TestLogWritesMessagesToLogGivenOverrideForLoggerReducingLogLevel(t *testing }) logMessage := "test log message" - logger.Warn(ctx, logMessage) + logger.Info(ctx, logMessage) logger.Flush() logLines, err := getLogLines(t, logPath) @@ -701,7 +679,7 @@ func TestLogWritesMessagesToLogGivenOverrideForLoggerReducingLogLevel(t *testing } assert.Equal(t, logMessage, logLines[0]["msg"]) - assert.Equal(t, "WARN", logLines[0]["level"]) + assert.Equal(t, "INFO", logLines[0]["level"]) assert.Equal(t, "TestLogName", logLines[0]["logger"]) // caller is disabled by default assert.NotContains(t, logLines[0], "logging_test.go") @@ -719,7 +697,7 @@ func TestLogWritesMessagesToLogGivenOverrideForLoggerRaisingLogLevel(t *testing. }) logMessage := "test log message" - logger.Warn(ctx, logMessage) + logger.Info(ctx, logMessage) logger.Flush() logLines, err := getLogLines(t, logPath) @@ -732,7 +710,7 @@ func TestLogWritesMessagesToLogGivenOverrideForLoggerRaisingLogLevel(t *testing. } assert.Equal(t, logMessage, logLines[0]["msg"]) - assert.Equal(t, "WARN", logLines[0]["level"]) + assert.Equal(t, "INFO", logLines[0]["level"]) assert.Equal(t, "TestLogName", logLines[0]["logger"]) // caller is disabled by default assert.NotContains(t, logLines[0], "logging_test.go") @@ -750,7 +728,7 @@ func TestLogDoesNotWriteMessagesToLogGivenOverrideForLoggerRaisingLogLevel(t *te }) logMessage := "test log message" - logger.Warn(ctx, logMessage) + logger.Info(ctx, logMessage) logger.Flush() logLines, err := getLogLines(t, logPath) @@ -775,7 +753,7 @@ func TestLogDoesNotWriteMessagesToLogGivenOverrideUpdatedForAnotherLoggerReducin }) logMessage := "test log message" - logger.Warn(ctx, logMessage) + logger.Info(ctx, logMessage) logger.Flush() logLines, err := getLogLines(t, logPath) @@ -800,7 +778,7 @@ func TestLogWritesMessagesToLogGivenOverrideUpdatedForLoggerReducingLogLevel(t * }) logMessage := "test log message" - logger.Warn(ctx, logMessage) + logger.Info(ctx, logMessage) logger.Flush() logLines, err := getLogLines(t, logPath) @@ -813,7 +791,7 @@ func TestLogWritesMessagesToLogGivenOverrideUpdatedForLoggerReducingLogLevel(t * } assert.Equal(t, logMessage, logLines[0]["msg"]) - assert.Equal(t, "WARN", logLines[0]["level"]) + assert.Equal(t, "INFO", logLines[0]["level"]) assert.Equal(t, "TestLogName", logLines[0]["logger"]) // caller is disabled by default assert.NotContains(t, logLines[0], "logging_test.go") @@ -833,7 +811,7 @@ func TestLogWritesMessagesToLogGivenOverrideUpdatedForAnotherLoggerRaisingLogLev }) logMessage := "test log message" - logger.Warn(ctx, logMessage) + logger.Info(ctx, logMessage) logger.Flush() logLines, err := getLogLines(t, logPath) @@ -846,7 +824,7 @@ func TestLogWritesMessagesToLogGivenOverrideUpdatedForAnotherLoggerRaisingLogLev } assert.Equal(t, logMessage, logLines[0]["msg"]) - assert.Equal(t, "WARN", logLines[0]["level"]) + assert.Equal(t, "INFO", logLines[0]["level"]) assert.Equal(t, "TestLogName", logLines[0]["logger"]) // caller is disabled by default assert.NotContains(t, logLines[0], "logging_test.go") @@ -866,7 +844,7 @@ func TestLogDoesNotWriteMessagesToLogGivenOverrideUpdatedForLoggerRaisingLogLeve }) logMessage := "test log message" - logger.Warn(ctx, logMessage) + logger.Info(ctx, logMessage) logger.Flush() logLines, err := getLogLines(t, logPath) diff --git a/net/peer.go b/net/peer.go index 472e114c7a..08f01f4121 100644 --- a/net/peer.go +++ b/net/peer.go @@ -167,7 +167,7 @@ func (p *Peer) Close() error { // from the internal broadcaster to the external pubsub network func (p *Peer) handleBroadcastLoop() { if p.bus == nil { - log.Warn(p.ctx, "Tried to start internal broadcaster with none defined") + log.Info(p.ctx, "Tried to start internal broadcaster with none defined") return } @@ -187,7 +187,7 @@ func (p *Peer) handleBroadcastLoop() { } else if msg.Priority > 1 { err = p.handleDocUpdateLog(msg) } else { - log.Warn(p.ctx, "Skipping log with invalid priority of 0", logging.NewKV("CID", msg.Cid)) + log.Info(p.ctx, "Skipping log with invalid priority of 0", logging.NewKV("CID", msg.Cid)) } if err != nil { @@ -462,7 +462,7 @@ func stopGRPCServer(ctx context.Context, server *grpc.Server) { select { case <-timer.C: server.Stop() - log.Warn(ctx, "Peer gRPC server was shutdown ungracefully") + log.Info(ctx, "Peer gRPC server was shutdown ungracefully") case <-stopped: timer.Stop() } diff --git a/tests/integration/utils.go b/tests/integration/utils.go index 3484074ec7..9c70ed0480 100644 --- a/tests/integration/utils.go +++ b/tests/integration/utils.go @@ -294,8 +294,7 @@ func ExecuteQueryTestCase( assert.NotEmpty(t, dbs) for _, dbi := range dbs { - // We log with level warn to highlight this item - log.Warn(ctx, test.Description, logging.NewKV("Database", dbi.name)) + log.Info(ctx, test.Description, logging.NewKV("Database", dbi.name)) if detectDbChanges { if setupOnly { @@ -639,8 +638,7 @@ func assertQueryResults( } resultantData := result.Data.([]map[string]interface{}) - // We log with level warn to highlight this item - log.Warn(ctx, "", logging.NewKV("QueryResults", result.Data)) + log.Info(ctx, "", logging.NewKV("QueryResults", result.Data)) // compare results assert.Equal(t, len(expectedResults), len(resultantData), description)