-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogging.bas
143 lines (79 loc) · 2.7 KB
/
Logging.bas
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
Attribute VB_Name = "Logging"
Option Explicit
Private started As Boolean
Private logFile As TextStream
Public Sub Start()
On Error GoTo HandleError
Set logFile = Utils.GetFileSystem().OpenTextFile(settings("logging.file"), ForAppending, True, TristateTrue)
started = True
LogSeparatorLine
LogInfoAt "Logging.start", "Logging turned on"
Exit Sub
HandleError:
DebugLastErrorAt "Logging.start"
End Sub
Public Sub DebugLastErrorAt(functionName)
Debug.Print "PPVoting error " & Err.Number & " in " & functionName & ": " & vbNewLine & Err.Description
End Sub
Public Sub LogLastErrorAt(functionName As String)
DebugLastErrorAt functionName
LogErrorAt functionName, Err.Number, Err.Description
End Sub
Public Sub LogErrorAt(procedure As String, errorNumber As Long, errorMessage As String)
On Error GoTo HandleError
If Not started Then Exit Sub
logFile.WriteLine "[" & Now() & "] ERROR (" & procedure & ") #" & errorNumber & ": " & errorMessage
Exit Sub
HandleError:
DebugLastErrorAt "Logging.LogErrorAt"
End Sub
Public Sub LogVotes(ByRef votes As Dictionary)
On Error GoTo HandleError
If Not started Then Exit Sub
logFile.Write "[" & Now() & "] INFO (votes): "
Dim i As Integer
For i = 1 To 7
logFile.Write CStr(votes("total")(i))
If i <> 7 Then logFile.Write ","
logFile.Write " "
Next i
logFile.WriteLine
If Not votes.Exists("votes") Then
LogInfoAt "Logging.logVotes", "Voting information is not detailed (no {ID->vote} info)"
Exit Sub
End If
Dim vote As Variant
For Each vote In votes("votes")
logFile.WriteLine "ID " & vote(1) & " voted for " & vote(2) + 1
Next vote
Exit Sub
HandleError:
DebugLastErrorAt "Logging.LogVotes"
End Sub
Public Sub LogInfoAt(procesure As String, errorMessage As String)
On Error GoTo HandleError
If Not started Then Exit Sub
logFile.WriteLine "[" & Now() & "] INFO (" & procesure & "): " & errorMessage
Exit Sub
HandleError:
DebugLastErrorAt "Logging.LogInfoAt"
End Sub
Public Sub LogSeparatorLine()
On Error GoTo HandleError
If Not started Then Exit Sub
logFile.WriteLine String(16, "-")
Exit Sub
HandleError:
DebugLastErrorAt "Logging.LogSeparatorLine"
End Sub
Public Sub Finish()
On Error GoTo HandleError
If Not started Then Exit Sub
LogInfoAt "Logging.Finish", "Logging turned off"
logFile.Close
started = False
Exit Sub
HandleError:
started = False
DebugLastErrorAt "Logging.Finish"
End Sub