From 81ac648d91ad5e42f9087c63be37e25e31b3da37 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 30 Jul 2023 19:12:33 +0200 Subject: [PATCH] log: add all log-levels that are accepted While other log-levels are not currently used in containerd itself, they can be returned by `GetLevel()`, and are accepted (no error) by `SetLevel()`. We should either accept those values, or produce an error (in `SetLevel()`), but given that there's other ways to set the log-level, we should probably acknowledge that this package is a transitional package, and still closely tied to logrus (for the time being). Signed-off-by: Sebastiaan van Stijn --- log/context.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/log/context.go b/log/context.go index 7d45348b7..ee94d55e0 100644 --- a/log/context.go +++ b/log/context.go @@ -60,6 +60,21 @@ const ( // InfoLevel level. General operational entries about what's going on // inside the application. InfoLevel Level = logrus.InfoLevel + + // WarnLevel level. Non-critical entries that deserve eyes. + WarnLevel Level = logrus.WarnLevel + + // ErrorLevel level. Logs errors that should definitely be noted. + // Commonly used for hooks to send errors to an error tracking service. + ErrorLevel Level = logrus.ErrorLevel + + // FatalLevel level. Logs and then calls "logger.Exit(1)". It exits + // even if the logging level is set to Panic. + FatalLevel Level = logrus.FatalLevel + + // PanicLevel level. This is the highest level of severity. Logs and + // then calls panic with the message passed to Debug, Info, ... + PanicLevel Level = logrus.PanicLevel ) // SetLevel sets log level globally. It returns an error if the given @@ -70,6 +85,10 @@ const ( // - "trace" ([TraceLevel]) // - "debug" ([DebugLevel]) // - "info" ([InfoLevel]) +// - "warn" ([WarnLevel]) +// - "error" ([ErrorLevel]) +// - "fatal" ([FatalLevel]) +// - "panic" ([PanicLevel]) func SetLevel(level string) error { lvl, err := logrus.ParseLevel(level) if err != nil {