diff options
author | Bjørn Erik Pedersen <[email protected]> | 2024-01-30 09:23:21 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2024-01-30 20:12:03 +0100 |
commit | 4e84f57efb57f5c8a850e4c1d562a0bcc7bd1700 (patch) | |
tree | 678ed4f283b67339c341ad355306ca0d5d771ad8 /common | |
parent | f31a6db797c9251a362ef9f8ad4c03fb608b5ac0 (diff) | |
download | hugo-4e84f57efb57f5c8a850e4c1d562a0bcc7bd1700.tar.gz hugo-4e84f57efb57f5c8a850e4c1d562a0bcc7bd1700.zip |
Add warnidf template function
Also rename config `ignoreErrors` => `ignoreLogs`
But the old still works.
Closes #9189
Diffstat (limited to 'common')
-rw-r--r-- | common/loggers/logger.go | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/common/loggers/logger.go b/common/loggers/logger.go index c4d81fb83..f851513b3 100644 --- a/common/loggers/logger.go +++ b/common/loggers/logger.go @@ -179,9 +179,9 @@ type Logger interface { Debugln(v ...any) Error() logg.LevelLogger Errorf(format string, v ...any) + Erroridf(id, format string, v ...any) Errorln(v ...any) Errors() string - Errorsf(id, format string, v ...any) Info() logg.LevelLogger InfoCommand(command string) logg.LevelLogger Infof(format string, v ...any) @@ -197,6 +197,7 @@ type Logger interface { Warn() logg.LevelLogger WarnCommand(command string) logg.LevelLogger Warnf(format string, v ...any) + Warnidf(id, format string, v ...any) Warnln(v ...any) Deprecatef(fail bool, format string, v ...any) Trace(s logg.StringFunc) @@ -321,10 +322,20 @@ func (l *logAdapter) Errors() string { return l.errors.String() } -func (l *logAdapter) Errorsf(id, format string, v ...any) { +func (l *logAdapter) Erroridf(id, format string, v ...any) { + format += l.idfInfoStatement("error", id, format) l.errorl.WithField(FieldNameStatementID, id).Logf(format, v...) } +func (l *logAdapter) Warnidf(id, format string, v ...any) { + format += l.idfInfoStatement("warning", id, format) + l.warnl.WithField(FieldNameStatementID, id).Logf(format, v...) +} + +func (l *logAdapter) idfInfoStatement(what, id, format string) string { + return fmt.Sprintf("\nYou can suppress this %s by adding the following to your site configuration:\nignoreLogs = ['%s']", what, id) +} + func (l *logAdapter) Trace(s logg.StringFunc) { l.tracel.Log(s) } |