forked from jlelse/GoBlog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.go
More file actions
43 lines (36 loc) · 737 Bytes
/
Copy pathlog.go
File metadata and controls
43 lines (36 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"log/slog"
"os"
)
func (a *goBlog) initLog() {
a.initLogOnce.Do(func() {
a.logLevel = new(slog.LevelVar)
a.logger = slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
Level: a.logLevel,
}))
})
}
func (a *goBlog) updateLogLevel() {
a.initLog()
if a.cfg.Debug {
a.logLevel.Set(slog.LevelDebug)
}
}
func (a *goBlog) debug(msg string, args ...any) {
a.initLog()
a.logger.Debug(msg, args...)
}
func (a *goBlog) info(msg string, args ...any) {
a.initLog()
a.logger.Info(msg, args...)
}
func (a *goBlog) error(msg string, args ...any) {
a.initLog()
a.logger.Error(msg, args...)
}
func (a *goBlog) fatal(msg string, args ...any) {
a.initLog()
a.error(msg, args...)
os.Exit(1)
}