-
Notifications
You must be signed in to change notification settings - Fork 3
/
M_omLogging.def
114 lines (105 loc) · 3.68 KB
/
M_omLogging.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
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Compare Database
Option Explicit
Public Enabled As Boolean
Public startDate As Date
Public endDate As Date
Public PreviousDate As Date
Public PreviousDescription As String
Public CurrentDescription As String
Private dtCurrent As Date
Private startTicks As Long
Private previousTicks As Long
Private currentTicks As Long
Private endTicks As Long
Dim ts As TextStream
Private Sub Class_Initialize()
Me.Reset
Set ts = gFso.CreateTextFile(gFso.BuildPath(CurrentProject.path, "log_" & omDateFunctions.GetTimeStamp() & ".txt"))
End Sub
Public Property Get currentdate() As Date
currentdate = dtCurrent
End Property
Public Sub SetCurrentDate(Optional dt As Date = 0, Optional Description As String = "")
If dt = 0 Then
dt = Now
End If
Me.currentdate = dt
Me.CurrentDescription = Description
End Sub
Public Property Let currentdate(ByVal vNewValue As Date)
PreviousDate = dtCurrent
PreviousDescription = CurrentDescription
previousTicks = currentTicks
dtCurrent = vNewValue
currentTicks = omKernalFunctions.GetTickCount()
If startDate = 0 Then
startDate = dtCurrent
PreviousDate = dtCurrent
startTicks = currentTicks
previousTicks = currentTicks
End If
If endDate < dtCurrent Then
endDate = dtCurrent
endTicks = currentTicks
End If
End Property
Public Function WriteToFile(Optional diffOnly As String = "y", Optional updateCurrentDate As Boolean = True, Optional Description As String = "") As String
'Dim ts As TextStream
If Not Enabled Then
Exit Function
End If
'Set ts = gFso.OpenTextFile(filename, ForAppending, True)
ts.WriteLine ToString(diffOnly, updateCurrentDate, Description)
ts.Close
Set ts = Nothing
End Function
Public Function ToString(Optional diffOnly As String = "y", Optional updateCurrentDate As Boolean = True, Optional Description As String = "") As String
If updateCurrentDate Then
SetCurrentDate Description:=Description
End If
If Not Enabled Then
Exit Function
End If
If Len(Description) > 0 Then
ToString = "Description: " & Description & vbCrLf
End If
If diffOnly = "n" Then
ToString = ToString & "StartDate: " & startDate & vbCrLf
ToString = ToString & "PreviousDate: " & PreviousDate & vbCrLf
ToString = ToString & "CurrentDate: " & currentdate & vbCrLf
ToString = ToString & "EndDate: " & endDate & vbCrLf
ToString = ToString & "StartTicks: " & startTicks & vbCrLf
ToString = ToString & "PreviousTicks: " & previousTicks & vbCrLf
ToString = ToString & "CurrentTicks: " & currentTicks & vbCrLf
ToString = ToString & "EndTicks: " & endTicks & vbCrLf
End If
ToString = ToString & "CurrentTicks - StartTicks: " & (currentTicks - startTicks) & vbCrLf
ToString = ToString & "CurrentTicks - PreviousTicks: " & (currentTicks - previousTicks) & vbCrLf
End Function
Public Function WriteToStream(Optional diffOnly As String = "y", Optional updateCurrentDate As Boolean = True, Optional Description As String = "") As String
WriteToStream = ToString(diffOnly, updateCurrentDate, Description)
If NotIsNullOrEmpty(WriteToStream) Then
ts.WriteLine WriteToStream
End If
End Function
Public Sub Reset()
Me.Enabled = False
startDate = 0
PreviousDate = 0
currentdate = 0
endDate = 0
startTicks = 0
previousTicks = 0
currentTicks = 0
endTicks = 0
PreviousDescription = ""
CurrentDescription = ""
End Sub
Private Sub Class_Terminate()
ts.Close
Set ts = Nothing
End Sub