forked from zqjzqj/mtSecKill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogs.go
52 lines (42 loc) · 974 Bytes
/
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
package logs
import (
"github.com/gookit/color"
"log"
"os"
)
var logger *log.Logger
func AllowFileLogs() {
logsFile, err := os.OpenFile("mtSecKill.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err == nil {
logger = log.New(logsFile, "", log.Lshortfile|log.LstdFlags)
}
}
//这个包用来统一的日志输出处理
//目前只做简单两个方法 后续根据具体需要在这里增加日志操作
func Println(v ...interface{}) {
if logger != nil {
logger.Println(v)
}
log.Println(v...)
}
func print2(color2 color.Color, v ...interface{}) {
if logger != nil {
logger.Println(v)
}
color2.Light().Println(v...)
}
func PrintlnSuccess(v ...interface{}) {
print2(color.Green, v...)
}
func PrintlnInfo(v ...interface{}) {
print2(color.LightCyan, v...)
}
func PrintlnWarning(v ...interface{}) {
print2(color.Yellow, v...)
}
func PrintErr(v ...interface{}) {
print2(color.FgLightRed, v...)
}
func Fatal(v ...interface{}) {
log.Fatal(v...)
}