1
mirror of https://github.com/jlelse/GoBlog synced 2024-07-15 11:02:58 +00:00
GoBlog/log.go
2023-12-27 11:37:58 +01:00

40 lines
678 B
Go

package main
import (
"log/slog"
"os"
)
func (a *goBlog) initLog() {
a.logLevel = new(slog.LevelVar)
a.logger = slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
Level: a.logLevel,
}))
}
func (a *goBlog) updateLogLevel() {
if a.logLevel == nil {
a.initLog()
}
if a.cfg.Debug {
a.logLevel.Set(slog.LevelDebug)
}
}
func (a *goBlog) debug(msg string, args ...any) {
a.logger.Debug(msg, args...)
}
func (a *goBlog) info(msg string, args ...any) {
a.logger.Info(msg, args...)
}
func (a *goBlog) error(msg string, args ...any) {
a.logger.Error(msg, args...)
}
func (a *goBlog) fatal(msg string, args ...any) {
a.error(msg, args...)
os.Exit(1)
}