From 1abadc549952ee7e0b3f6be230b6e15eb6ef0d4b Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Thu, 14 Dec 2023 20:26:06 +0100 Subject: [PATCH] add "warn" log level now that we are using slog, which has them. and we already could use them for a deprecation warning. --- mlog/log.go | 14 ++++++++++++++ mox-/config.go | 2 +- webadmin/admin.html | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/mlog/log.go b/mlog/log.go index be1acbf..6619ef4 100644 --- a/mlog/log.go +++ b/mlog/log.go @@ -71,6 +71,7 @@ var ( LevelTrace = slog.LevelDebug - 4 LevelDebug = slog.LevelDebug LevelInfo = slog.LevelInfo + LevelWarn = slog.LevelWarn LevelError = slog.LevelError LevelFatal = slog.LevelError + 4 // Printed regardless of configured log level. LevelPrint = slog.LevelError + 8 // Printed regardless of configured log level. @@ -83,6 +84,7 @@ var LevelStrings = map[slog.Level]string{ LevelTrace: "trace", LevelDebug: "debug", LevelInfo: "info", + LevelWarn: "warn", LevelError: "error", LevelFatal: "fatal", LevelPrint: "print", @@ -95,6 +97,7 @@ var Levels = map[string]slog.Level{ "trace": LevelTrace, "debug": LevelDebug, "info": LevelInfo, + "warn": LevelWarn, "error": LevelError, "fatal": LevelFatal, "print": LevelPrint, @@ -207,6 +210,17 @@ func (l Log) Infox(msg string, err error, attrs ...slog.Attr) { l.Logger.LogAttrs(noctx, LevelInfo, msg, attrs...) } +func (l Log) Warn(msg string, attrs ...slog.Attr) { + l.Logger.LogAttrs(noctx, LevelWarn, msg, attrs...) +} + +func (l Log) Warnx(msg string, err error, attrs ...slog.Attr) { + if err != nil { + attrs = append([]slog.Attr{errAttr(err)}, attrs...) + } + l.Logger.LogAttrs(noctx, LevelWarn, msg, attrs...) +} + func (l Log) Error(msg string, attrs ...slog.Attr) { l.Logger.LogAttrs(noctx, LevelError, msg, attrs...) } diff --git a/mox-/config.go b/mox-/config.go index 1e689d7..2ee6dba 100644 --- a/mox-/config.go +++ b/mox-/config.go @@ -1343,7 +1343,7 @@ func prepareDynamicConfig(ctx context.Context, log mlog.Log, dynamicPath string, if !ok { addErrorf("could not find localpart %q to replace with address in destinations", lp) } else { - log.Error(`deprecation warning: support for account destination addresses specified as just localpart ("username") instead of full email address will be removed in the future; update domains.conf, for each Account, for each Destination, ensure each key is an email address by appending "@" and the default domain for the account`, + log.Warn(`deprecation warning: support for account destination addresses specified as just localpart ("username") instead of full email address will be removed in the future; update domains.conf, for each Account, for each Destination, ensure each key is an email address by appending "@" and the default domain for the account`, slog.Any("localpart", lp), slog.Any("address", addr), slog.String("account", accName)) diff --git a/webadmin/admin.html b/webadmin/admin.html index 19706df..03be74b 100644 --- a/webadmin/admin.html +++ b/webadmin/admin.html @@ -301,7 +301,7 @@ const config = async () => { const loglevels = async () => { const loglevels = await api.LogLevels() - const levels = ['error', 'info', 'debug', 'trace', 'traceauth', 'tracedata'] + const levels = ['error', 'info', 'warn', 'debug', 'trace', 'traceauth', 'tracedata'] let form, fieldset, pkg, level