initial commit
This commit is contained in:
57
logger/logger.go
Normal file
57
logger/logger.go
Normal file
@ -0,0 +1,57 @@
|
||||
package logger
|
||||
|
||||
import "sync"
|
||||
|
||||
const (
|
||||
logFieldScope = "scope"
|
||||
)
|
||||
|
||||
// LogLevel is Logger Level type
|
||||
type LogLevel string
|
||||
|
||||
const (
|
||||
// DebugLevel has verbose message
|
||||
DebugLevel LogLevel = "debug"
|
||||
// InfoLevel is default log level
|
||||
InfoLevel LogLevel = "info"
|
||||
// WarnLevel is for logging messages about possible issues
|
||||
WarnLevel LogLevel = "warn"
|
||||
// ErrorLevel is for logging errors
|
||||
ErrorLevel LogLevel = "error"
|
||||
// FatalLevel is for logging fatal messages. The system shuts down after logging the message.
|
||||
FatalLevel LogLevel = "fatal"
|
||||
)
|
||||
|
||||
var (
|
||||
globalLoggers = make(map[string]Logger)
|
||||
globalLoggersLock sync.RWMutex
|
||||
)
|
||||
|
||||
type Logger interface {
|
||||
EnableJSONOutput(enabled bool)
|
||||
SetLevel(level LogLevel)
|
||||
WithFields(map[string]interface{}) Logger
|
||||
Debug(args ...interface{})
|
||||
Debugf(format string, args ...interface{})
|
||||
Info(args ...interface{})
|
||||
Infof(format string, args ...interface{})
|
||||
Warn(args ...interface{})
|
||||
Warnf(format string, args ...interface{})
|
||||
Error(args ...interface{})
|
||||
Errorf(format string, args ...interface{})
|
||||
Fatal(args ...interface{})
|
||||
Fatalf(format string, args ...interface{})
|
||||
}
|
||||
|
||||
func NewLogger(name string) Logger {
|
||||
globalLoggersLock.Lock()
|
||||
defer globalLoggersLock.Unlock()
|
||||
|
||||
logger, ok := globalLoggers[name]
|
||||
if !ok {
|
||||
logger = newLogger(name)
|
||||
globalLoggers[name] = logger
|
||||
}
|
||||
|
||||
return logger
|
||||
}
|
Reference in New Issue
Block a user