move config & logging packages into internal submodules
This commit is contained in:
parent
e525b7ff3b
commit
450d425b04
5 changed files with 62 additions and 38 deletions
42
internal/logging/logging.go
Normal file
42
internal/logging/logging.go
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue