This commit is contained in:
Eden Kirin
2024-06-18 22:01:31 +02:00
commit 21dcabe180
21 changed files with 1039 additions and 0 deletions

View File

@ -0,0 +1,65 @@
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))
}
*/
}