finclip-app-manager/infrastructure/logger/logger.go

42 lines
637 B
Go
Raw Permalink Normal View History

2023-10-31 14:07:26 +08:00
package logger
import (
"encoding/json"
"finclip-app-manager/infrastructure/config"
)
var l *Logger
func init() {
cfg := config.GetConfig()
time := true
file := true
debug := cfg.DebugLog
trace := cfg.TraceLog
colors := true
pid := false
if cfg.LogFile == "" {
l = NewStdLogger(time, file, debug, trace, colors, pid)
} else {
l = NewFileLogger(cfg.LogFile, time, file, debug, trace, pid)
}
}
func GetLogger() *Logger {
return l
}
type Fields map[string]interface{}
func IJS(obj Fields) string {
jsonBytes, err := json.MarshalIndent(obj, "", " ")
if err == nil {
return string(jsonBytes)
}
return ""
}