forked from caicloud/nirvana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.go
135 lines (111 loc) · 4.09 KB
/
default.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
Copyright 2017 Caicloud Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package log
// default logger. Don't use the logger directly.
var logger Logger = newStderrLogger(LevelDebug, 1)
// DefaultLogger returns default logger.
func DefaultLogger() Logger {
return logger.Clone(-1)
}
// SetDefaultLogger sets default logger.
func SetDefaultLogger(l Logger) {
if l == nil {
logger = &SilentLogger{}
} else {
logger = l.Clone(1)
}
}
type defaultVerboser struct {
verboser Verboser
}
// Info logs to the INFO log.
// Arguments are handled in the manner of fmt.Println; a newline is appended if missing.
func (v *defaultVerboser) Info(a ...interface{}) {
v.verboser.Info(a...)
}
// Infof logs to the INFO log.
// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.
func (v *defaultVerboser) Infof(format string, a ...interface{}) {
v.verboser.Infof(format, a...)
}
// Infoln logs to the INFO log.
// Arguments are handled in the manner of fmt.Println; a newline is appended if missing.
func (v *defaultVerboser) Infoln(a ...interface{}) {
v.verboser.Infoln(a...)
}
// V reports whether verbosity at the call site is at least the requested level.
// The returned value is a Verboser, which implements Info, Infof
// and Infoln. These methods will write to the Info log if called.
func V(v Level) Verboser {
return &defaultVerboser{logger.V(v)}
}
// Info logs to the INFO log.
// Arguments are handled in the manner of fmt.Println; a newline is appended if missing.
func Info(a ...interface{}) {
logger.Info(a...)
}
// Infof logs to the INFO log.
// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.
func Infof(format string, a ...interface{}) {
logger.Infof(format, a...)
}
// Infoln logs to the INFO log.
// Arguments are handled in the manner of fmt.Println; a newline is appended if missing.
func Infoln(a ...interface{}) {
logger.Infoln(a...)
}
// Warning logs to the WARNING logs.
// Arguments are handled in the manner of fmt.Print; a newline is appended if missing.
func Warning(a ...interface{}) {
logger.Warning(a...)
}
// Warningf logs to the WARNING logs.
// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.
func Warningf(format string, a ...interface{}) {
logger.Warningf(format, a...)
}
// Warningln logs to the WARNING logs.
// Arguments are handled in the manner of fmt.Println; a newline is appended if missing.
func Warningln(a ...interface{}) {
logger.Warningln(a...)
}
// Error logs to the ERROR logs.
// Arguments are handled in the manner of fmt.Print; a newline is appended if missing.
func Error(a ...interface{}) {
logger.Error(a...)
}
// Errorf logs to the ERROR logs.
// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.
func Errorf(format string, a ...interface{}) {
logger.Errorf(format, a...)
}
// Errorln logs to the ERROR logs.
// Arguments are handled in the manner of fmt.Println; a newline is appended if missing.
func Errorln(a ...interface{}) {
logger.Errorln(a...)
}
// Fatal logs to the FATAL logs, then calls os.Exit(1).
// Arguments are handled in the manner of fmt.Print; a newline is appended if missing.
func Fatal(a ...interface{}) {
logger.Fatal(a...)
}
// Fatalf logs to the FATAL logs, then calls os.Exit(1).
// Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.
func Fatalf(format string, a ...interface{}) {
logger.Fatalf(format, a...)
}
// Fatalln logs to the FATAL logs, then calls os.Exit(1).
// Arguments are handled in the manner of fmt.Println; a newline is appended if missing.
func Fatalln(a ...interface{}) {
logger.Fatalln(a...)
}