package log
import (
"context"
"fmt"
"io"
"log"
"os"
)
var logger AllLogger = &defaultLogger {
stdlog : log .New (os .Stderr , "" , log .LstdFlags |log .Lshortfile |log .Lmicroseconds ),
depth : 4 ,
}
type Logger interface {
Trace (v ...interface {})
Debug (v ...interface {})
Info (v ...interface {})
Warn (v ...interface {})
Error (v ...interface {})
Fatal (v ...interface {})
Panic (v ...interface {})
}
type FormatLogger interface {
Tracef (format string , v ...interface {})
Debugf (format string , v ...interface {})
Infof (format string , v ...interface {})
Warnf (format string , v ...interface {})
Errorf (format string , v ...interface {})
Fatalf (format string , v ...interface {})
Panicf (format string , v ...interface {})
}
type WithLogger interface {
Tracew (msg string , keysAndValues ...interface {})
Debugw (msg string , keysAndValues ...interface {})
Infow (msg string , keysAndValues ...interface {})
Warnw (msg string , keysAndValues ...interface {})
Errorw (msg string , keysAndValues ...interface {})
Fatalw (msg string , keysAndValues ...interface {})
Panicw (msg string , keysAndValues ...interface {})
}
type CommonLogger interface {
Logger
FormatLogger
WithLogger
}
type ControlLogger interface {
SetLevel (Level )
SetOutput (io .Writer )
}
type AllLogger interface {
CommonLogger
ControlLogger
WithContext (ctx context .Context ) CommonLogger
}
type Level int
const (
LevelTrace Level = iota
LevelDebug
LevelInfo
LevelWarn
LevelError
LevelFatal
LevelPanic
)
var strs = []string {
"[Trace] " ,
"[Debug] " ,
"[Info] " ,
"[Warn] " ,
"[Error] " ,
"[Fatal] " ,
"[Panic] " ,
}
func (lv Level ) toString () string {
if lv >= LevelTrace && lv <= LevelPanic {
return strs [lv ]
}
return fmt .Sprintf ("[?%d] " , lv )
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .