From d55985637e1484309b09e76d29f04f2c7258c3de Mon Sep 17 00:00:00 2001 From: Devon Bear Date: Sat, 30 Dec 2023 06:30:35 -0500 Subject: [PATCH] feat(log): add `warn` log level (#18898) Co-authored-by: marbar3778 --- log/CHANGELOG.md | 1 + log/logger.go | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/log/CHANGELOG.md b/log/CHANGELOG.md index 486a4016eb..ffea96df0f 100644 --- a/log/CHANGELOG.md +++ b/log/CHANGELOG.md @@ -24,6 +24,7 @@ Each entry must include the Github issue reference in the following format: * [#18916](https://github.com/cosmos/cosmos-sdk/pull/18916) Introduce an option for setting hooks. * [#18429](https://github.com/cosmos/cosmos-sdk/pull/18429) Support customization of log json marshal. +* [#18898](https://github.com/cosmos/cosmos-sdk/pull/18898) Add `WARN` level. ## [v1.2.1](https://github.com/cosmos/cosmos-sdk/releases/tag/log/v1.2.1) - 2023-08-25 diff --git a/log/logger.go b/log/logger.go index 1d4cab1447..4fbb9b296b 100644 --- a/log/logger.go +++ b/log/logger.go @@ -40,6 +40,10 @@ type Logger interface { // The key of the tuple must be a string. Info(msg string, keyVals ...any) + // Warn takes a message and a set of key/value pairs and logs with level WARN. + // The key of the tuple must be a string. + Warn(msg string, keyVals ...any) + // Error takes a message and a set of key/value pairs and logs with level ERR. // The key of the tuple must be a string. Error(msg string, keyVals ...any) @@ -140,6 +144,12 @@ func (l zeroLogWrapper) Info(msg string, keyVals ...interface{}) { l.Logger.Info().Fields(keyVals).Msg(msg) } +// Info takes a message and a set of key/value pairs and logs with level INFO. +// The key of the tuple must be a string. +func (l zeroLogWrapper) Warn(msg string, keyVals ...interface{}) { + l.Logger.Warn().Fields(keyVals).Msg(msg) +} + // Error takes a message and a set of key/value pairs and logs with level DEBUG. // The key of the tuple must be a string. func (l zeroLogWrapper) Error(msg string, keyVals ...interface{}) { @@ -176,6 +186,7 @@ func NewNopLogger() Logger { type nopLogger struct{} func (nopLogger) Info(string, ...any) {} +func (nopLogger) Warn(string, ...any) {} func (nopLogger) Error(string, ...any) {} func (nopLogger) Debug(string, ...any) {} func (nopLogger) With(...any) Logger { return nopLogger{} }