-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
124 lines (113 loc) · 2.98 KB
/
types.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
121
122
123
124
// Package logtor provides constants and utility functions related to logging, including LogLevel constants,
// LogCreatorName type, color codes for different log levels, and functions for color formatting and checking
// whether a log level is acceptable based on a selected level.
//
// Variables:
// - ResetColor: ANSI escape code to reset color.
// - NoneColor, FatalColor, ErrorColor, WarnColor, DebugColor, InfoColor, TraceColor:
// ANSI escape codes for log level colors.
//
// Constants:
// - LogLevel: Represents different log levels (NONE, FATAL, ERROR, WARN, DEBUG, INFO, TRACE).
// - LogCreatorName: Represents the names of log creators.
// - Color Codes: ANSI escape codes for log level colors.
//
// Functions:
// - GetColorForLogLevel: Returns the ANSI escape code for the color associated with a log level.
// - IsLogLevelAcceptable: Checks if a given log level is acceptable based on the selected log level.
package types
type LogLevel string
const (
NONE LogLevel = "NONE"
FATAL LogLevel = "FATAL"
ERROR LogLevel = "ERROR"
WARN LogLevel = "WARN"
DEBUG LogLevel = "DEBUG"
INFO LogLevel = "INFO"
TRACE LogLevel = "TRACE"
)
var LogLevelList = []LogLevel{NONE, FATAL, ERROR, WARN, DEBUG, INFO, TRACE}
type LogCreatorName string
var (
ResetColor = "\033[0m"
NoneColor = "\033[97m"
FatalColor = "\033[31m"
ErrorColor = "\033[31m"
WarnColor = "\033[33m"
DebugColor = "\033[32m"
InfoColor = "\033[34m"
TraceColor = "\033[35m"
)
func GetColorForLogLevel(level LogLevel) string {
switch level {
case FATAL:
return FatalColor
case ERROR:
return ErrorColor
case WARN:
return WarnColor
case DEBUG:
return DebugColor
case INFO:
return InfoColor
case TRACE:
return TraceColor
default:
return ResetColor
}
}
func IsLogLevelAcceptable(selected, using LogLevel) bool {
switch selected {
case FATAL:
if using == FATAL {
return true
}
return false
case ERROR:
if using == FATAL || using == ERROR {
return true
}
return false
case WARN:
if using == FATAL || using == ERROR || using == WARN {
return true
}
return false
case DEBUG:
if using == FATAL || using == ERROR || using == WARN || using == DEBUG {
return true
}
return false
case INFO:
if using == FATAL || using == ERROR || using == WARN || using == DEBUG || using == INFO {
return true
}
return false
case TRACE:
if using == FATAL || using == ERROR || using == WARN || using == DEBUG || using == INFO || using == TRACE {
return true
}
return false
default:
return false
}
}
func (d LogLevel) IsValid() bool {
levels := GetLogLevelList()
_, ok := levels[d]
return ok
}
func (d LogLevel) IsLogLevelAcceptable(level LogLevel) bool {
return IsLogLevelAcceptable(d, level)
}
func GetLogLevelList() map[LogLevel]struct{} {
return map[LogLevel]struct{}{
FATAL: {},
ERROR: {},
WARN: {},
DEBUG: {},
INFO: {},
TRACE: {},
NONE: {},
}
}