aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2022-11-23 00:41:33 +0100
committerRobin Jarry <robin@jarry.cc>2022-12-02 22:10:17 +0100
commite88aea5ee68598d7716c788061490062eb7130dd (patch)
tree092f3b573073770d2a8ee0c616ab57b5289b66b8
parent118ece70af51a677f1504ec1ca13e47d0db5fc67 (diff)
downloadaerc-e88aea5ee68598d7716c788061490062eb7130dd.tar.gz
logging: add new trace log level
We need more logging granularity. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Bence Ferdinandy <bence@ferdinandy.com> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
-rw-r--r--doc/aerc-config.5.scd6
-rw-r--r--logging/logger.go17
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