move config & logging packages into internal submodules

This commit is contained in:
Piper Pentagram 2024-11-06 16:01:38 -08:00
parent e525b7ff3b
commit 450d425b04
5 changed files with 62 additions and 38 deletions

View file

@ -0,0 +1,42 @@
package logging
import (
"log/slog"
"path/filepath"
"gitlab.com/whom/bingobot/internal/config"
"gopkg.in/natefinch/lumberjack.v2"
)
type Logger struct {
*slog.Logger
}
var (
logger Logger
)
func InitLogger(appConfig *config.AppConfig) Logger {
lj := &lumberjack.Logger{
Filename: filepath.Join(appConfig.LogDir, appConfig.LogFile),
MaxSize: appConfig.LogMaxSizeMB,
MaxBackups: appConfig.LogMaxBackups,
MaxAge: appConfig.LogMaxAgeDays,
Compress: appConfig.LogCompression,
}
logger = Logger{
slog.New(
slog.NewJSONHandler(lj, &slog.HandlerOptions{
AddSource: appConfig.LogAddSource,
}),
),
}
return logger
}
func GetLogger() Logger {
return logger
}