-
Notifications
You must be signed in to change notification settings - Fork 74
/
log.go
75 lines (61 loc) · 1.2 KB
/
log.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
package log
import (
"fmt"
"log"
"os"
)
var (
logger = log.New(os.Stdout, "", log.Ldate|log.Ltime)
loggerErr = log.New(os.Stderr, "", log.Ldate|log.Ltime)
level = ERROR
)
func SetLevel(newLevel LogLevel) {
level = newLevel
}
type Message interface {
String() string
}
// Write a simple logger
func Write(msg Message) {
logger.Print(msg.String() + "\n")
}
func D(format string, v ...interface{}) {
print(format, v...)
}
func Debug(format Message, v ...interface{}) {
D(format.String(), v...)
}
func I(format string, v ...interface{}) {
if INFO < level {
return
}
print(format, v...)
}
func W(format string, v ...interface{}) {
if WARNING < level {
return
}
print(format, v...)
}
func Warnln(format string, v ...interface{}) {
W(format, v)
}
func E(format string, v ...interface{}) {
printErr(format, v...)
}
func Error(format Message, v ...interface{}) {
E(format.String(), v...)
}
func print(msg string, args ...interface{}) {
// m := fmt.Sprintf(msg, args...)
for _, arg := range args {
msg += fmt.Sprintf(" %v", arg)
}
logger.Println(msg)
}
func printErr(msg string, args ...interface{}) {
for _, arg := range args {
msg += fmt.Sprintf(" %v", arg)
}
loggerErr.Println(msg)
}