diff options
author | n-peugnet <n.peugnet@free.fr> | 2021-09-22 19:47:27 +0200 |
---|---|---|
committer | n-peugnet <n.peugnet@free.fr> | 2021-09-22 20:44:24 +0200 |
commit | a1b768438258bfd6c33573e156708f002c693ba2 (patch) | |
tree | 0ce9ef80263061e746fe10d93058b106cb93ee1f /logger/logger.go | |
parent | 368f89466f48e8621254b04c1bca996db5c7a66a (diff) | |
download | dna-backup-a1b768438258bfd6c33573e156708f002c693ba2.tar.gz dna-backup-a1b768438258bfd6c33573e156708f002c693ba2.zip |
add debug log level
Diffstat (limited to 'logger/logger.go')
-rw-r--r-- | logger/logger.go | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/logger/logger.go b/logger/logger.go index bd8b937..9613e17 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -20,15 +20,18 @@ type logger interface { // Severity levels. const ( - sInfo severity = iota + sDebug severity = iota + sInfo sWarning sError sFatal + sCount ) // Severity tags. const ( - tagInfo = "\033[0m[INFO] " + tagDebug = "\033[0m[DEBUG] " + tagInfo = "\033[97m[INFO] " tagWarning = "\033[33m[WARN] " tagError = "\033[31m[ERROR] " tagFatal = "\033[1;31m[FATAL] " @@ -44,8 +47,9 @@ var ( defaultLogger *Logger ) -func newLoggers() [4]logger { - return [4]logger{ +func newLoggers() [sCount]logger { + return [sCount]logger{ + log.New(os.Stderr, tagDebug, flags), log.New(os.Stderr, tagInfo, flags), log.New(os.Stderr, tagWarning, flags), log.New(os.Stderr, tagError, flags), @@ -90,7 +94,7 @@ func Init(level int) *Logger { // A Logger represents an active logging object. Multiple loggers can be used // simultaneously even if they are using the same writers. type Logger struct { - loggers [4]logger + loggers [sCount]logger minSeverity severity initialized bool } @@ -129,6 +133,18 @@ func (l *Logger) SetFlags(flag int) { } } +// Debug logs with the Info severity. +// Arguments are handled in the manner of fmt.Print. +func (l *Logger) Debug(v ...interface{}) { + l.output(sDebug, v...) +} + +// Debugf logs with the Info severity. +// Arguments are handled in the manner of fmt.Printf. +func (l *Logger) Debugf(format string, v ...interface{}) { + l.outputf(sDebug, format, v...) +} + // Info logs with the Info severity. // Arguments are handled in the manner of fmt.Print. func (l *Logger) Info(v ...interface{}) { @@ -209,6 +225,18 @@ func SetFlags(flag int) { defaultLogger.SetFlags(flag) } +// Debug uses the default logger and logs with the Info severity. +// Arguments are handled in the manner of fmt.Print. +func Debug(v ...interface{}) { + defaultLogger.output(sDebug, v...) +} + +// Debugf uses the default logger and logs with the Info severity. +// Arguments are handled in the manner of fmt.Printf. +func Debugf(format string, v ...interface{}) { + defaultLogger.outputf(sDebug, format, v...) +} + // Info uses the default logger and logs with the Info severity. // Arguments are handled in the manner of fmt.Print. func Info(v ...interface{}) { |