-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogType.go
164 lines (147 loc) · 6.01 KB
/
logType.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package jobrunner
import (
"sort"
"strings"
)
// LogType is the entry type of logging
type LogType int
// These are the enum definitions of log types and presets
const (
LogTypeProcessEnter LogType = 1 << iota
LogTypeProcessRequest
LogTypeMethodEnter
LogTypeMethodParameter
LogTypeMethodLogic
LogTypeWebcallStart
LogTypeWebcallRequest
LogTypeWebcallResponse
LogTypeWebcallFinish
LogTypeMethodReturn
LogTypeMethodExit
LogTypeProcessResponse
LogTypeProcessExit
LogTypeBasicTracing LogType = LogTypeMethodLogic
LogTypeGeneralTracing LogType = LogTypeBasicTracing | LogTypeProcessEnter | LogTypeProcessExit
LogTypeVerboseTracing LogType = LogTypeGeneralTracing | LogTypeWebcallStart | LogTypeWebcallFinish
LogTypeFullTracing LogType = LogTypeVerboseTracing | LogTypeMethodEnter | LogTypeMethodExit
LogTypeBasicDebugging LogType = LogTypeMethodLogic
LogTypeGeneralDebugging LogType = LogTypeBasicDebugging | LogTypeProcessRequest | LogTypeProcessResponse
LogTypeVerboseDebugging LogType = LogTypeGeneralDebugging | LogTypeWebcallRequest | LogTypeWebcallResponse
LogTypeFullDebugging LogType = LogTypeVerboseDebugging | LogTypeMethodParameter | LogTypeMethodReturn
LogTypeBasicLogging LogType = LogTypeBasicTracing | LogTypeBasicDebugging
LogTypeGeneralLogging LogType = LogTypeBasicLogging | LogTypeGeneralTracing | LogTypeGeneralDebugging
LogTypeVerboseLogging LogType = LogTypeGeneralLogging | LogTypeVerboseTracing | LogTypeVerboseDebugging
LogTypeFullLogging LogType = LogTypeVerboseLogging | LogTypeFullTracing | LogTypeFullDebugging
LogTypeAppRoot LogType = 0
)
// These are the string representations of log category and preset names
const (
apiEnterLogTypeName string = "ProcessEnter"
apiRequestLogTypeName string = "ProcessRequest"
methodEnterLogTypeName string = "MethodEnter"
methodParameterLogTypeName string = "MethodParameter"
methodLogicLogTypeName string = "MethodLogic"
webcallCallLogTypeName string = "WebcallStart"
webcallRequestLogTypeName string = "WebcallRequest"
webcallResponseLogTypeName string = "WebcallResponse"
webcallFinishLogTypeName string = "WebcallFinish"
methodReturnLogTypeName string = "MethodReturn"
methodExitLogTypeName string = "MethodExit"
apiResponseLogTypeName string = "ProcessResponse"
apiExitLogTypeName string = "ProcessExit"
basicTracingLogTypeName string = "BasicTracing"
generalTracingLogTypeName string = "GeneralTracing"
verboseTracingLogTypeName string = "VerboseTracing"
fullTracingLogTypeName string = "FullTracing"
basicDebuggingLogTypeName string = "BasicDebugging"
generalDebuggingLogTypeName string = "GeneralDebugging"
verboseDebuggingLogTypeName string = "VerboseDebugging"
fullDebuggingLogTypeName string = "FullDebugging"
basicLoggingLogTypeName string = "BasicLogging"
generalLoggingLogTypeName string = "GeneralLogging"
verboseLoggingLogTypeName string = "VerboseLogging"
fullLoggingLogTypeName string = "FullLogging"
appRootLogTypeName string = "AppRoot"
)
var supportedLogTypes = map[LogType]string{
LogTypeProcessEnter: apiEnterLogTypeName,
LogTypeProcessRequest: apiRequestLogTypeName,
LogTypeMethodEnter: methodEnterLogTypeName,
LogTypeMethodParameter: methodParameterLogTypeName,
LogTypeMethodLogic: methodLogicLogTypeName,
LogTypeWebcallStart: webcallCallLogTypeName,
LogTypeWebcallRequest: webcallRequestLogTypeName,
LogTypeWebcallResponse: webcallResponseLogTypeName,
LogTypeWebcallFinish: webcallFinishLogTypeName,
LogTypeMethodReturn: methodReturnLogTypeName,
LogTypeMethodExit: methodExitLogTypeName,
LogTypeProcessResponse: apiResponseLogTypeName,
LogTypeProcessExit: apiExitLogTypeName,
}
var logTypeNameMapping = map[string]LogType{
apiEnterLogTypeName: LogTypeProcessEnter,
apiRequestLogTypeName: LogTypeProcessRequest,
methodEnterLogTypeName: LogTypeMethodEnter,
methodParameterLogTypeName: LogTypeMethodParameter,
methodLogicLogTypeName: LogTypeMethodLogic,
webcallCallLogTypeName: LogTypeWebcallStart,
webcallRequestLogTypeName: LogTypeWebcallRequest,
webcallResponseLogTypeName: LogTypeWebcallResponse,
webcallFinishLogTypeName: LogTypeWebcallFinish,
methodReturnLogTypeName: LogTypeMethodReturn,
methodExitLogTypeName: LogTypeMethodExit,
apiResponseLogTypeName: LogTypeProcessResponse,
apiExitLogTypeName: LogTypeProcessExit,
basicTracingLogTypeName: LogTypeBasicTracing,
generalTracingLogTypeName: LogTypeGeneralTracing,
verboseTracingLogTypeName: LogTypeVerboseTracing,
fullTracingLogTypeName: LogTypeFullTracing,
basicDebuggingLogTypeName: LogTypeBasicDebugging,
generalDebuggingLogTypeName: LogTypeGeneralDebugging,
verboseDebuggingLogTypeName: LogTypeVerboseDebugging,
fullDebuggingLogTypeName: LogTypeFullDebugging,
basicLoggingLogTypeName: LogTypeBasicLogging,
generalLoggingLogTypeName: LogTypeGeneralLogging,
verboseLoggingLogTypeName: LogTypeVerboseLogging,
fullLoggingLogTypeName: LogTypeFullLogging,
appRootLogTypeName: LogTypeAppRoot,
}
// FromString converts a LogType flag instance to its string representation
func (logtype LogType) String() string {
if logtype == LogTypeAppRoot {
return appRootLogTypeName
}
var result []string
for key, value := range supportedLogTypes {
if logtype&key == key {
result = append(result, value)
}
}
sort.Strings(result)
return strings.Join(result, "|")
}
// HasFlag checks whether this log category has the flag set or not
func (logtype LogType) HasFlag(flag LogType) bool {
if flag == LogTypeAppRoot {
return true
}
if logtype&flag == flag {
return true
}
return false
}
// NewLogType converts a string representation of LogType flag to its strongly typed instance
func NewLogType(value string) LogType {
var splitValues = strings.Split(
value,
"|",
)
var combinedLogType LogType
for _, splitValue := range splitValues {
var logType, found = logTypeNameMapping[splitValue]
if found {
combinedLogType = combinedLogType | logType
}
}
return combinedLogType
}