Make logging package usage less tedious

Before, we were exposing a Logger as logging.Log. This works, but
results in code calling Logger.Log.Info() which is a little wordy.

Instead, the logger is now kept private and we expose Info, Warn and
Error as public functions that wrap logger.Info, logger.Warn and
logger.Error.
This commit is contained in:
Piper Pentagram 2024-11-08 14:33:57 -08:00
parent 5e4273390f
commit 665717d9e7
2 changed files with 18 additions and 6 deletions

View file

@ -13,7 +13,7 @@ type Logger struct {
}
var (
Log Logger
logger Logger
)
func Init(appConfig *config.AppConfig) {
@ -26,7 +26,7 @@ func Init(appConfig *config.AppConfig) {
Compress: appConfig.LogCompression,
}
Log = Logger{
logger = Logger{
slog.New(
slog.NewJSONHandler(lj, &slog.HandlerOptions{
AddSource: appConfig.LogAddSource,
@ -34,3 +34,15 @@ func Init(appConfig *config.AppConfig) {
),
}
}
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...)
}