-
Notifications
You must be signed in to change notification settings - Fork 22
/
log.go
120 lines (104 loc) · 3.65 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
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
109
110
111
112
113
114
115
116
117
118
119
120
/**
* Filename: log.go
* Description: the log information format
* Author: knownsec404
* Time: 2020.08.17
*/
package main
import (
"fmt"
"time"
)
const (
LOG_LEVEL_NONE uint32 = 0
LOG_LEVEL_FATAL uint32 = 1
LOG_LEVEL_ERROR uint32 = 2
LOG_LEVEL_WARN uint32 = 3
LOG_LEVEL_INFO uint32 = 4
LOG_LEVEL_DEBUG uint32 = 5
)
var LOG_LEVEL uint32 = LOG_LEVEL_DEBUG
/**********************************************************************
* @Function: LogFatal(format string, a ...interface{})
* @Description: log infomations with fatal level
* @Parameter: format string, the format string template
* @Parameter: a ...interface{}, the value
* @Return: nil
**********************************************************************/
func LogFatal(format string, a ...interface{}) {
if LOG_LEVEL < LOG_LEVEL_FATAL {
return
}
msg := fmt.Sprintf(format, a...)
msg = fmt.Sprintf("[%s] [FATAL] %s", getCurrentTime(), msg)
fmt.Println(msg)
}
/**********************************************************************
* @Function: LogError(format string, a ...interface{})
* @Description: log infomations with error level
* @Parameter: format string, the format string template
* @Parameter: a ...interface{}, the value
* @Return: nil
**********************************************************************/
func LogError(format string, a ...interface{}) {
if LOG_LEVEL < LOG_LEVEL_WARN {
return
}
msg := fmt.Sprintf(format, a...)
msg = fmt.Sprintf("[%s] [ERROR] %s", getCurrentTime(), msg)
fmt.Println(msg)
}
/**********************************************************************
* @Function: LogWarn(format string, a ...interface{})
* @Description: log infomations with warn level
* @Parameter: format string, the format string template
* @Parameter: a ...interface{}, the value
* @Return: nil
**********************************************************************/
func LogWarn(format string, a ...interface{}) {
if LOG_LEVEL < LOG_LEVEL_WARN {
return
}
msg := fmt.Sprintf(format, a...)
msg = fmt.Sprintf("[%s] [WARN] %s", getCurrentTime(), msg)
fmt.Println(msg)
}
/**********************************************************************
* @Function: LogInfo(format string, a ...interface{})
* @Description: log infomations with info level
* @Parameter: format string, the format string template
* @Parameter: a ...interface{}, the value
* @Return: nil
**********************************************************************/
func LogInfo(format string, a ...interface{}) {
if LOG_LEVEL < LOG_LEVEL_INFO {
return
}
msg := fmt.Sprintf(format, a...)
msg = fmt.Sprintf("[%s] [INFO] %s", getCurrentTime(), msg)
fmt.Println(msg)
}
/**********************************************************************
* @Function: LogDebug(format string, a ...interface{})
* @Description: log infomations with debug level
* @Parameter: format string, the format string template
* @Parameter: a ...interface{}, the value
* @Return: nil
**********************************************************************/
func LogDebug(format string, a ...interface{}) {
if LOG_LEVEL < LOG_LEVEL_DEBUG {
return
}
msg := fmt.Sprintf(format, a...)
msg = fmt.Sprintf("[%s] [DEBUG] %s", getCurrentTime(), msg)
fmt.Println(msg)
}
/**********************************************************************
* @Function: getCurrentTime() (string)
* @Description: get current time as log format string
* @Parameter: nil
* @Return: string, the current time string
**********************************************************************/
func getCurrentTime() (string) {
return time.Now().Format("01-02|15:04:05")
}