bingobot/internal/logging/logging.go
Piper Pentagram 9f678b6be7 Remove source info from log messages
slog.HandlerOptions.AddSource is a cool feature, but since we moved the
logger to a separate package it no longer works. It now always shows
source info for the log package, rather than the code that called it.

This change removes it.
2024-11-13 17:02:47 -08:00

51 lines
818 B
Go

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 Init() {
cfg := config.Get()
lj := &lumberjack.Logger{
Filename: filepath.Join(cfg.LogDir, cfg.LogFile),
MaxSize: cfg.LogMaxSizeMB,
MaxBackups: cfg.LogMaxBackups,
MaxAge: cfg.LogMaxAgeDays,
Compress: cfg.LogCompression,
}
logger = Logger{
slog.New(
slog.NewJSONHandler(lj, &slog.HandlerOptions{}),
),
}
}
func Debug(msg string, args ...any) {
logger.Debug(msg, args...)
}
func Info(msg string, args ...any) {
logger.Info(msg, args...)
}
func Warn(msg string, args ...any) {
logger.Warn(msg, args...)
}
func Error(msg string, args ...any) {
logger.Error(msg, args...)
}