From e88aea5ee68598d7716c788061490062eb7130dd Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Wed, 23 Nov 2022 00:41:33 +0100 Subject: logging: add new trace log level We need more logging granularity. Signed-off-by: Robin Jarry Tested-by: Bence Ferdinandy Acked-by: Tim Culverhouse --- doc/aerc-config.5.scd | 6 +++--- logging/logger.go | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd index 247490ab..40825864 100644 --- a/doc/aerc-config.5.scd +++ b/doc/aerc-config.5.scd @@ -54,9 +54,9 @@ These options are configured in the *[general]* section of _aerc.conf_. *log-level* Only log messages above the specified level to *log-file*. Supported - levels are: _debug_, _info_, _warn_ and _error_. When redirecting aerc's - output to a file using _>_ shell redirection, this setting is ignored - and the log level is forced to _debug_. + levels are: _trace_, _debug_, _info_, _warn_ and _error_. When + redirecting aerc's output to a file using _>_ shell redirection, this + setting is ignored and the log level is forced to _debug_. Default: _info_ diff --git a/logging/logger.go b/logging/logger.go index 47dd3ba6..da548c07 100644 --- a/logging/logger.go +++ b/logging/logger.go @@ -11,6 +11,7 @@ import ( type LogLevel int const ( + TRACE LogLevel = 5 DEBUG LogLevel = 10 INFO LogLevel = 20 WARN LogLevel = 30 @@ -18,17 +19,19 @@ const ( ) var ( + trace *log.Logger dbg *log.Logger info *log.Logger warn *log.Logger err *log.Logger - minLevel LogLevel = DEBUG + minLevel LogLevel = TRACE ) func Init(file *os.File, level LogLevel) { minLevel = level flags := log.Ldate | log.Ltime | log.Lmicroseconds | log.Lshortfile | log.LUTC if file != nil { + trace = log.New(file, "TRACE ", flags) dbg = log.New(file, "DEBUG ", flags) info = log.New(file, "INFO ", flags) warn = log.New(file, "WARN ", flags) @@ -38,6 +41,8 @@ func Init(file *os.File, level LogLevel) { func ParseLevel(value string) (LogLevel, error) { switch strings.ToLower(value) { + case "trace": + return TRACE, nil case "debug": return DEBUG, nil case "info": @@ -57,6 +62,16 @@ func ErrorLogger() *log.Logger { return err } +func Tracef(message string, args ...interface{}) { + if trace == nil || minLevel > TRACE { + return + } + if len(args) > 0 { + message = fmt.Sprintf(message, args...) + } + trace.Output(2, message) //nolint:errcheck // we can't do anything with what we log +} + func Debugf(message string, args ...interface{}) { if dbg == nil || minLevel > DEBUG { return -- cgit