-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogger.go
108 lines (91 loc) · 3.08 KB
/
logger.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
package terra
import "log"
type Logger interface {
// Trace arguments are handled in the manner of fmt.Printf.
Trace(format string, v ...interface{})
// Debug arguments are handled in the manner of fmt.Printf.
Debug(format string, v ...interface{})
// Info arguments are handled in the manner of fmt.Printf.
Info(format string, v ...interface{})
// Warn arguments are handled in the manner of fmt.Printf.
Warn(format string, v ...interface{})
// Error arguments are handled in the manner of fmt.Printf.
Error(format string, v ...interface{})
// Fatal arguments are handled in the manner of fmt.Printf.
Fatal(format string, v ...interface{})
// Panic arguments are handled in the manner of fmt.Printf.
Panic(format string, v ...interface{})
}
type DefaultLogger struct {
l Logger
}
// Trace calls log.Printf or log.Println (if there is no
// additional arguments) to print to the standard logger.
// Arguments are handled in the manner of fmt.Printf.
func (DefaultLogger) Trace(format string, v ...interface{}) {
if len(v) > 0 {
log.Printf("[Trace] "+format, v...)
} else {
log.Println("[Trace] " + format)
}
}
// Debug calls log.Printf or log.Println (if there is no
// additional arguments) to print to the standard logger.
// Arguments are handled in the manner of fmt.Printf.
func (DefaultLogger) Debug(format string, v ...interface{}) {
if len(v) > 0 {
log.Printf("[Debug] "+format, v...)
} else {
log.Println("[Debug] " + format)
}
}
// Info calls log.Printf or log.Println (if there is no
// additional arguments) to print to the standard logger.
// Arguments are handled in the manner of fmt.Printf.
func (DefaultLogger) Info(format string, v ...interface{}) {
if len(v) > 0 {
log.Printf("[Info] "+format, v...)
} else {
log.Println("[Info] " + format)
}
}
// Warn calls log.Printf or log.Println (if there is no
// additional arguments) to print to the standard logger.
// Arguments are handled in the manner of fmt.Printf.
func (DefaultLogger) Warn(format string, v ...interface{}) {
if len(v) > 0 {
log.Printf("[Warn] "+format, v...)
} else {
log.Println("[Warn] " + format)
}
}
// Error calls log.Printf or log.Println (if there is no
// additional arguments) to print to the standard logger.
// Arguments are handled in the manner of fmt.Printf.
func (DefaultLogger) Error(format string, v ...interface{}) {
if len(v) > 0 {
log.Printf("[Error] "+format, v...)
} else {
log.Println("[Error] " + format)
}
}
// Fatal calls log.Fatalf or log.Fatalln (if there is no
// additional arguments) to print to the standard logger.
// Arguments are handled in the manner of fmt.Printf.
func (DefaultLogger) Fatal(format string, v ...interface{}) {
if len(v) > 0 {
log.Fatalf("[Trace] "+format, v...)
} else {
log.Fatalln("[Trace] " + format)
}
}
// Panic calls log.Panicf or log.Panicln (if there is no
// additional arguments) to print to the standard logger.
// Arguments are handled in the manner of fmt.Printf.
func (DefaultLogger) Panic(format string, v ...interface{}) {
if len(v) > 0 {
log.Panicf("[Trace] "+format, v...)
} else {
log.Panicln("[Trace] " + format)
}
}