/
root.go
69 lines (53 loc) · 1.49 KB
/
root.go
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
58
59
60
61
62
63
64
65
66
67
68
69
package log
import (
"fmt"
"os"
)
var (
root = &logger{[]interface{}{}, new(swapHandler)}
StdoutHandler = StreamHandler(os.Stdout, LogfmtFormat())
StderrHandler = StreamHandler(os.Stderr, LogfmtFormat())
)
func init() {
root.SetHandler(DiscardHandler())
}
func New(ctx ...interface{}) Logger {
return root.New(ctx...)
}
func Root() Logger {
return root
}
func Trace(msg string, ctx ...interface{}) {
root.write(msg, LvlTrace, ctx, skipLevel)
}
func Debug(msg string, ctx ...interface{}) {
root.write(msg, LvlDebug, ctx, skipLevel)
}
func Info(msg string, ctx ...interface{}) {
root.write(msg, LvlInfo, ctx, skipLevel)
}
func Warn(msg string, ctx ...interface{}) {
root.write(msg, LvlWarn, ctx, skipLevel)
}
func Error(msg string, ctx ...interface{}) {
root.write(msg, LvlError, ctx, skipLevel)
}
func Crit(msg string, ctx ...interface{}) {
root.write(msg, LvlCrit, ctx, skipLevel)
os.Exit(1)
}
func Output(msg string, lvl Lvl, calldepth int, ctx ...interface{}) {
root.write(msg, lvl, ctx, calldepth+skipLevel)
}
func Debugf(format string, args ...interface{}) {
root.write(fmt.Sprintf(format, args...), LvlDebug, nil, skipLevel)
}
func Infof(format string, args ...interface{}) {
root.write(fmt.Sprintf(format, args...), LvlInfo, nil, skipLevel)
}
func Warnf(format string, args ...interface{}) {
root.write(fmt.Sprintf(format, args...), LvlWarn, nil, skipLevel)
}
func Errorf(format string, args ...interface{}) {
root.write(fmt.Sprintf(format, args...), LvlError, nil, skipLevel)
}