66 lines
1.3 KiB
Go
66 lines
1.3 KiB
Go
package logging
|
|
|
|
import (
|
|
"repo-pattern/app/lib/cfg"
|
|
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
var Log *zap.Logger = nil
|
|
|
|
func Init() {
|
|
var err error
|
|
|
|
logConfig := zap.NewProductionConfig()
|
|
logConfig.Level, err = zap.ParseAtomicLevel(cfg.Config.Application.LogLevel)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
logConfig.OutputPaths = []string{
|
|
cfg.Config.Application.LogFile,
|
|
"stderr",
|
|
}
|
|
|
|
Log, err = logConfig.Build()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
/*
|
|
logLevel, err := logrus.ParseLevel(cfg.Config.Application.LogLevel)
|
|
if err != nil {
|
|
panic(fmt.Sprintf("Invalid configured logLevel: %s\n", cfg.Config.Application.LogLevel))
|
|
}
|
|
|
|
Log.SetLevel(logLevel)
|
|
|
|
Log.SetFormatter(&logrus.TextFormatter{
|
|
FullTimestamp: true,
|
|
TimestampFormat: "2006-01-02 15:04:05",
|
|
PadLevelText: true,
|
|
DisableQuote: true,
|
|
})
|
|
|
|
LogFile := cfg.Config.Application.LogFile
|
|
file, err := os.OpenFile(
|
|
LogFile,
|
|
os.O_CREATE|os.O_WRONLY|os.O_APPEND,
|
|
0655,
|
|
)
|
|
if err != nil {
|
|
msg := fmt.Sprintf("Failed to log to file %s: %s", cfg.Config.Application.LogFile, err)
|
|
Log.Warning(msg)
|
|
panic(msg)
|
|
}
|
|
|
|
mw := io.MultiWriter(os.Stdout, file)
|
|
Log.SetOutput(mw)
|
|
|
|
configJson, err := json.Marshal(cfg.Config)
|
|
if err == nil {
|
|
Info(fmt.Sprintf("Using config: %s", configJson))
|
|
}
|
|
*/
|
|
}
|