aboutsummaryrefslogtreecommitdiffstats
path: root/logging
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 /logging
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>
Diffstat (limited to 'logging')
-rw-r--r--logging/logger.go17
1 files changed, 16 insertions, 1 deletions
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