Add JSON structured logging

This commit is contained in:
Piper Pentagram 2024-11-06 14:19:45 -08:00
parent 60b9d77873
commit c06d77485c
6 changed files with 51 additions and 6 deletions

27
log.go Normal file
View file

@ -0,0 +1,27 @@
package main
import (
"log/slog"
"path/filepath"
"gopkg.in/natefinch/lumberjack.v2"
)
var (
Log *slog.Logger
)
func initLogger() {
lj := &lumberjack.Logger{
Filename: filepath.Join(appConfig.LogDir, appConfig.LogFile),
MaxSize: appConfig.LogMaxSizeMB,
MaxBackups: appConfig.LogMaxBackups,
MaxAge: appConfig.LogMaxAgeDays,
Compress: appConfig.LogCompression,
}
Log = slog.New(slog.NewJSONHandler(lj, &slog.HandlerOptions{
AddSource: true,
}))
}