-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathM_clsLogSaver_Console.def
133 lines (106 loc) · 3.56 KB
/
M_clsLogSaver_Console.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
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'---------------------------------------------------------------------------------------
' Module : clsLogSaver_Console
' Author : K.Gundermann
' Date : 17.01.2012
' Purpose : Prints Logger Events to the Debugger Console
'---------------------------------------------------------------------------------------
Option Compare Database
Option Explicit
Implements ILogSaver
Private WithEvents c_Logger As clsLogger
Attribute c_Logger.VB_VarHelpID = -1
Private WithEvents c_Session As clsLogSession
Attribute c_Session.VB_VarHelpID = -1
Private c_Filters As clsLogFilterCollection
Private c_Name As String
Private Sub Class_Initialize()
Set c_Session = Logger.Log.Session
End Sub
Private Sub Class_Terminate()
Call StopLog
Set c_Session = Nothing
Set c_Filters = Nothing
End Sub
' --- Public Interface ---
Public Sub StartLog()
Set c_Logger = Logger.Log
End Sub
Public Sub StopLog()
Set c_Logger = Nothing
End Sub
Public Sub SaveToLog(ByRef objLogEntry As clsLogEntry)
If Filters.MatchFilter(objLogEntry) Then
Call SaveToConsole(objLogEntry)
End If
End Sub
Public Function AddFilter(ByVal TheFilter As clsLogFilter) As ILogSaver
Filters.AddFilter TheFilter
Set AddFilter = Me
End Function
Public Property Get ID() As Long
ID = ObjPtr(Me)
End Property
Public Property Get Name() As String
If c_Name = vbNullString Then
Name = TypeName(Me)
Else
Name = c_Name
End If
End Property
Public Property Let Name(ByVal TheName As String)
c_Name = TheName
End Property
' --- Private Functions ---
Private Property Get Filters() As clsLogFilterCollection
If c_Filters Is Nothing Then Set c_Filters = New clsLogFilterCollection
Set Filters = c_Filters
End Property
' --- Event Handler for Logger/Session Class ---
Private Sub c_Logger_SaveToLog(objLogEntry As clsLogEntry)
Call SaveToLog(objLogEntry)
End Sub
Private Sub c_Session_Login()
' ToDo: We have now a logged In User
End Sub
Private Sub c_Session_Logout()
' ToDo: The user has logged out
End Sub
' --- Implements ILogSaver ---
Private Sub ILogSaver_StartLog()
Me.StartLog
End Sub
Private Sub ILogSaver_StopLog()
Me.StopLog
End Sub
Private Function ILogSaver_AddFilter(ByVal TheFilter As clsLogFilter) As ILogSaver
Set ILogSaver_AddFilter = Me.AddFilter(TheFilter)
End Function
Private Property Get ILogSaver_ID() As Long
ILogSaver_ID = Me.ID
End Property
Private Property Get ILogSaver_Name() As String
ILogSaver_Name = Me.Name
End Property
Private Property Let ILogSaver_Name(ByVal TheName As String)
Me.Name = TheName
End Property
Private Sub ILogSaver_SaveToLog(objLogEntry As clsLogEntry)
Call SaveToLog(objLogEntry)
End Sub
' ---------------------------------------------------------------------------------
' -- Specific Functions for that logger here
Private Sub SaveToConsole(ByRef objLogEntry As clsLogEntry)
Dim str As String
With objLogEntry
If .Severity = Sev_Trace Then
str = SPrintF("%s %-10s,%-10s,%-10s,%-10s,%-10s,%-s,%-s", .TimeStamp.ToString(dt_Time), .SeverityText, .Category, .Module, .Procedure, .EventTypeText, .MessageText, .AdditionalInfo)
Else
str = SPrintF("%s %-10s,%-10s,%-10s,%-10s,%-10s,%-s", .TimeStamp.ToString(dt_Time), .SeverityText, .Category, .Module, .Procedure, .MessageNumber, .MessageText)
End If
End With
Debug.Print str
End Sub