-
Notifications
You must be signed in to change notification settings - Fork 0
/
std.go
100 lines (80 loc) · 1.72 KB
/
std.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
package logx
import (
"bytes"
"io"
"os"
)
var std *Logger
func init() {
//default std
std = New().SetLevel(LevelTest).SetColor(true).SetCallDepthPlus().SetWriter(os.Stdout).SetFlag(StdFlags)
}
// SetColor returns std
func SetColor(color bool) *Logger {
std.SetColor(color)
return std
}
func SetWriter(w io.Writer) *Logger {
std.SetWriter(w)
return std
}
// Info info v
// logx.Info("test")
func Info(v ...interface{}) {
std.Info(getFormat(len(v)), v...)
}
// Debug debug v
func Debug(v ...interface{}) {
std.Debug(getFormat(len(v)), v...)
}
// Error error v
func Error(v ...interface{}) {
std.Error(getFormat(len(v)), v...)
}
// Warn warn v
func Warn(v ...interface{}) {
std.Warn(getFormat(len(v)), v...)
}
// Fatal Fatal v
func Fatal(v ...interface{}) {
std.Fatal(getFormat(len(v)), v...)
}
// Panic Panic v
func Panic(v ...interface{}) {
std.Panic(getFormat(len(v)), v...)
}
// Notice notice v
func Notice(v ...interface{}) {
std.Notice(getFormat(len(v)), v...)
}
// Infof need format
// logy.Infof("user :%s",user.Username)
func Infof(format string, v ...interface{}) {
std.Info(format, v...)
}
func Noticef(format string, v ...interface{}) {
std.Notice(format, v...)
}
func Debugf(format string, v ...interface{}) {
std.Debug(format, v...)
}
func Warnf(format string, v ...interface{}) {
std.Warn(format, v...)
}
func Errorf(format string, v ...interface{}) {
std.Error(format, v...)
}
func Panicf(format string, v ...interface{}) {
std.Panic(format, v...)
}
func Fatalf(format string, v ...interface{}) {
std.Fatal(format, v...)
}
// getFormat returns format string
func getFormat(length int) string {
buffer := &bytes.Buffer{}
for i := 0; i < length; i++ {
buffer.WriteString("%v")
}
return buffer.String()
}