-
Notifications
You must be signed in to change notification settings - Fork 1
/
golog.go
117 lines (94 loc) · 2.7 KB
/
golog.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Better logging for Go.
package golog
import (
"flag"
)
var Global *PackageLogger
func init() {
Global = &PackageLogger{
failFunc: ExitError,
outer: NewDefaultMultiLogOuter(),
}
logger := NewLogger(
Global.outer,
defaultMinLogLevel,
func() { Global.failFunc() })
// Prints everything this level and above.
flag.Var(logger, "golog.minloglevel",
"Log messages at or above this level. The "+
"numbers of severity levels INFO, WARNING, "+
"ERROR, and FATAL are 0, 1, 2, and 3, respectively")
Global.logger = NewLocationLogger(logger,
MakeMetadataFunc(DefaultMetadata))
}
// Wrapper for Global.Info().
func Info(msg ...interface{}) {
Global.logger.LogDepth(INFO, printClosure(msg...), 1)
}
// Wrapper for Global.Infof().
func Infof(fmt string, vals ...interface{}) {
Global.logger.LogDepth(INFO, printfClosure(fmt, vals...), 1)
}
// Wrapper for Global.Infoc().
func Infoc(closure func() string) {
Global.logger.LogDepth(INFO, closure, 1)
}
// Wrapper for Global.Warning().
func Warning(msg ...interface{}) {
Global.logger.LogDepth(WARNING, printClosure(msg...), 1)
}
// Wrapper for Global.Warningf().
func Warningf(fmt string, vals ...interface{}) {
Global.logger.LogDepth(WARNING, printfClosure(fmt, vals...), 1)
}
// Wrapper for Global.Warningc().
func Warningc(closure func() string) {
Global.logger.LogDepth(WARNING, closure, 1)
}
// Wrapper for Global.Error().
func Error(msg ...interface{}) {
Global.logger.LogDepth(ERROR, printClosure(msg...), 1)
}
// Wrapper for Global.Errorf().
func Errorf(fmt string, vals ...interface{}) {
Global.logger.LogDepth(ERROR, printfClosure(fmt, vals...), 1)
}
// Wrapper for Global.Errorc().
func Errorc(closure func() string) {
Global.logger.LogDepth(ERROR, closure, 1)
}
// Wrapper for Global.Fatal().
func Fatal(msg ...interface{}) {
Global.logger.LogDepth(FATAL, printClosure(msg...), 1)
Global.logger.FailNow()
}
// Wrapper for Global.Fatalf().
func Fatalf(fmt string, vals ...interface{}) {
Global.logger.LogDepth(FATAL, printfClosure(fmt, vals...), 1)
Global.logger.FailNow()
}
// Wrapper for Global.Fatalc().
func Fatalc(closure func() string) {
Global.logger.LogDepth(FATAL, closure, 1)
Global.logger.FailNow()
}
// Wrapper for Global.StartTestLogging().
func StartTestLogging(t TestController) {
Global.StartTestLogging(t)
}
// Wrapper for Global.StopTestLogging().
func StopTestLogging() {
Global.StopTestLogging()
}
// Wrapper for Global.AddLogOuter().
func AddLogOuter(key string, outer LogOuter) {
Global.AddLogOuter(key, outer)
}
// Wrapper for Global.RemoveLogOuter().
func RemoveLogOuter(key string) {
Global.RemoveLogOuter(key)
}
// Wrapper for Global.SetMinLogLevel().
func SetMinLogLevel(level int) {
Global.SetMinLogLevel(level)
}