-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathM_clsLogEntry.def
219 lines (187 loc) · 6.57 KB
/
M_clsLogEntry.def
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
'---------------------------------------------------------------------------------------
' Module : clsLogEntry
' Author : K.Gundermann + Paul Rohorzka
' Date : 17.01.2012
' Purpose : Defines a Log Entry
'---------------------------------------------------------------------------------------
Option Compare Database
Option Explicit
Public Enum e_Severity
Sev_Critical = 1
Sev_Error = 2
Sev_Informational = 4
Sev_Trace = 8
Sev_Debug = 16
Sev_All = 1 + 2 + 4 + 8 + 16
End Enum
Public Enum e_EventType ' Only for Sev_Trace
Evt_Status = 1
Evt_Entering = 2
Evt_Leaving = 4
Evt_Creating = 8
Evt_Destroying = 16
Evt_Performance = 32
Evt_All = 1 + 2 + 4 + 8 + 16 + 32
Evt_EnterLeave = 2 + 4
Evt_CreateDestroy = 8 + 16
End Enum
Private Type t_LogEntry
ts As SYSTEMTIME
TimeStamp As clsDateTime
Category As String
Module As String
Procedure As String
Severity As e_Severity
EventType As e_EventType
MessageNumber As Long
MessageText As String
MessageDisplayed As Boolean
AdditionalInfo As String
End Type
Private z As t_LogEntry
Private z_Empty As t_LogEntry
Private Declare Sub api_GetLocalTime Lib "kernel32" Alias "GetLocalTime" (lpSystemTime As SYSTEMTIME)
Public Sub Init(Optional ByVal Category As String, Optional ByVal Module As String, Optional ByVal Procedure As String, _
Optional ByVal Severity As e_Severity = Sev_Informational, Optional ByVal EventType As e_EventType = Evt_Status, _
Optional ByVal MessageNumber As Long, Optional ByVal MessageText As String, _
Optional ByVal AdditionalInfo As String, _
Optional ByVal MessageDisplayed As Boolean)
Set z.TimeStamp = Nothing
' Set z.Timestamp = OS.Time.Now ' Creating an object is expensive
api_GetLocalTime z.ts
z.Category = Category
z.Module = Module
z.Procedure = Procedure
z.Severity = Severity
z.EventType = EventType
z.MessageNumber = MessageNumber
z.MessageText = MessageText
z.AdditionalInfo = AdditionalInfo
z.MessageDisplayed = MessageDisplayed
End Sub
'Public Sub Reset()
' Set z.TimeStamp = Nothing
' z = z_Empty
'End Sub
' ---------------------------------------------------------------------------------------------
Public Property Get TimeStamp() As clsDateTime
If z.TimeStamp Is Nothing Then
' Set z.Timestamp = OS.Time.Now
Set z.TimeStamp = New clsDateTime
z.TimeStamp.FromSystemTime z.ts
End If
Set TimeStamp = z.TimeStamp
End Property
Public Property Set TimeStamp(ByVal TheValue As clsDateTime)
Set z.TimeStamp = TheValue
End Property
Public Property Get Category() As String
Category = z.Category
End Property
Public Property Let Category(ByVal TheValue As String)
z.Category = TheValue
End Property
Public Property Get Module() As String
Module = z.Module
End Property
Public Property Let Module(ByVal TheValue As String)
z.Module = TheValue
End Property
Public Property Get Procedure() As String
Procedure = z.Procedure
End Property
Public Property Let Procedure(ByVal TheValue As String)
z.Procedure = TheValue
End Property
Public Property Get Severity() As e_Severity
Severity = z.Severity
End Property
Public Property Let Severity(ByVal TheValue As e_Severity)
z.Severity = TheValue
End Property
Public Property Get EventType() As e_EventType
EventType = z.EventType
End Property
Public Property Let EventType(ByVal TheValue As e_EventType)
z.EventType = TheValue
End Property
Public Property Get MessageNumber() As Long
MessageNumber = z.MessageNumber
End Property
Public Property Let MessageNumber(ByVal TheValue As Long)
z.MessageNumber = TheValue
End Property
Public Property Get MessageText() As String
MessageText = z.MessageText
End Property
Public Property Let MessageText(ByVal TheValue As String)
z.MessageText = TheValue
End Property
Public Property Get AdditionalInfo() As String
AdditionalInfo = z.AdditionalInfo
End Property
Public Property Let AdditionalInfo(ByVal TheValue As String)
z.AdditionalInfo = TheValue
End Property
Public Property Get MessageDisplayed() As Boolean
MessageDisplayed = z.MessageDisplayed
End Property
Public Property Let MessageDisplayed(ByVal TheValue As Boolean)
z.MessageDisplayed = TheValue
End Property
' ---------------------------------------------------------------------------------------------
Public Property Get SeverityText() As String
Select Case Severity
Case Sev_Critical: SeverityText = "Critical"
Case Sev_Error: SeverityText = "Error"
Case Sev_Informational: SeverityText = "Information"
Case Sev_Trace: SeverityText = "Trace"
Case Sev_Debug: SeverityText = "Debug"
Case Else: SeverityText = "Unknown"
End Select
End Property
Public Property Get EventTypeText() As String
'If Me.Severity = Sev_Trace Then
Select Case EventType
Case Evt_Creating: EventTypeText = "Create"
Case Evt_Destroying: EventTypeText = "Destroy"
Case Evt_Entering: EventTypeText = "Enter"
Case Evt_Leaving: EventTypeText = "Leave"
Case Evt_Status: EventTypeText = "Status"
Case Evt_Performance: EventTypeText = "Perf"
End Select
'End If
End Property
Public Function ToString() As String
With Me
ToString = "" _
& "Timestamp: " & .TimeStamp.ToString & vbCrLf _
& "Category:" & .Category & vbCrLf _
& "Module: " & .Module & vbCrLf _
& "Procedure: " & .Procedure & vbCrLf _
& "EventType: " & .EventTypeText & vbCrLf _
& "Severity: " & .SeverityText & vbCrLf _
& "MessageNumber: " & .MessageNumber & vbCrLf _
& "MessageText: " & .MessageText & vbCrLf _
& "MessageDisplayed: " & .MessageDisplayed & vbCrLf _
& "AdditionalInfo: " & .AdditionalInfo & vbCrLf
End With
End Function
' ---------------------------------------------------------------------------------------------
Public Property Get Self() As clsLogEntry
Set Self = Me
End Property
Public Function Clone() As clsLogEntry
Set Clone = New clsLogEntry
Clone.SetConfig z
End Function
Friend Sub SetConfig(ByRef Config As t_LogEntry)
z = Config
If IsSomething(Config.TimeStamp) Then
Set z.TimeStamp = Config.TimeStamp.Clone
End If
End Sub