Add JSON structured logging
This commit is contained in:
parent
60b9d77873
commit
c06d77485c
6 changed files with 51 additions and 6 deletions
27
log.go
Normal file
27
log.go
Normal 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,
|
||||
}))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue