-
Notifications
You must be signed in to change notification settings - Fork 9
/
logs.go
68 lines (56 loc) · 1.14 KB
/
logs.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
package logs
import (
"log"
"os"
"time"
"github.com/gookit/color"
)
var IsPrintLog = true
var IsDebugPrint = true
const DateTimeFormatStr = "2006-01-02 15:04:05"
// 这个包用来统一的日志输出处理
// 目前只做简单两个方法 后续根据具体需要在这里增加日志操作
func Println(v ...interface{}) {
if IsPrintLog {
log.Println(v...)
}
}
func print2(color2 color.Color, v ...interface{}) {
s := time.Now().Format(DateTimeFormatStr)
v = append([]interface{}{"[" + s + "]"}, v...)
color2.Light().Println(v...)
}
func PrintDebug(v ...interface{}) {
if IsDebugPrint {
print2(color.Cyan, v...)
}
}
func PrintDebugErr(v ...interface{}) {
if IsDebugPrint {
print2(color.FgLightRed, v...)
}
}
func PrintlnSuccess(v ...interface{}) {
if IsPrintLog {
print2(color.Green, v...)
}
}
func PrintlnInfo(v ...interface{}) {
if IsPrintLog {
print2(color.LightCyan, v...)
}
}
func PrintlnWarning(v ...interface{}) {
if IsPrintLog {
print2(color.Yellow, v...)
}
}
func PrintErr(v ...interface{}) {
if IsPrintLog {
print2(color.FgLightRed, v...)
}
}
func Fatal(v ...interface{}) {
PrintErr(v...)
os.Exit(1)
}