-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroot.go
More file actions
57 lines (45 loc) · 832 Bytes
/
root.go
File metadata and controls
57 lines (45 loc) · 832 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package log
import (
"log/slog"
"os"
"sync"
)
var (
lock sync.RWMutex
root Logger
)
func init() {
root = NewLogger(NewTerminalHandler(os.Stdout, LevelDebug))
}
func SetDefault(l Logger) {
lock.Lock()
defer lock.Unlock()
root = l
if lg, ok := l.(*logger); ok {
slog.SetDefault(lg.logger)
}
}
func Root() Logger {
lock.RLock()
defer lock.RUnlock()
return root
}
func New(ctx ...interface{}) Logger {
return Root().With(ctx...)
}
func Debug(msg string, ctx ...interface{}) {
Root().Debug(msg, ctx...)
}
func Info(msg string, ctx ...interface{}) {
Root().Info(msg, ctx...)
}
func Warn(msg string, ctx ...interface{}) {
Root().Warn(msg, ctx...)
}
func Error(msg string, ctx ...interface{}) {
Root().Error(msg, ctx...)
}
func Crit(msg string, ctx ...interface{}) {
Root().Crit(msg, ctx...)
os.Exit(1)
}