-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLogModule.xojo_code
More file actions
167 lines (134 loc) · 4.56 KB
/
LogModule.xojo_code
File metadata and controls
167 lines (134 loc) · 4.56 KB
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
#tag Module
Protected Module LogModule
#tag Method, Flags = &h0
Function formatReadLogResult(timestampStr as String, loglevelStr as String, subsystemStr as String, logMsgStr as String) As String
Const col02SpacingStr as String = " "
Const col04SpacingStr as String = " "
Const col06SpacingStr as String = " "
Return timestampStr + col02SpacingStr + loglevelStr + col04SpacingStr + subsystemStr + col06SpacingStr + logMsgStr + EndOfLine
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function formatWriteLogResult(timestampStr as String, loglevelStr as String, subsystemStr as String, logMsgStr as String) As String
Return timestampStr + "," + loglevelStr + "," + subsystemStr + "," + logMsgStr + EndOfLine
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function systemLog(logfacility as Integer, subsystem as String, message as String) As Boolean
Var isProcessedBln as Boolean
Var thisDateTime as New Date
Var thisDateTimeStr as String = Str(thisDateTime)
Select Case userLogFacilityLevelInt
Case 0
// Do Nothing as Facilty Log Level 0 means Logging Disabled
Case 1
if logfacility = 1 Then
isProcessedBln = writeLogFile(thisDateTimeStr, logfacility, subsystem,message)
end if
Case 2
if logfacility = 1 OR logfacility = 2 Then
isProcessedBln = writeLogFile(thisDateTimeStr, logfacility,subsystem,message)
end if
Case 3
if logfacility = 1 OR logfacility = 2 OR logfacility = 3 Then
isProcessedBln = writeLogFile(thisDateTimeStr, logfacility,subsystem,message)
end if
Case 4
if logfacility = 1 OR logfacility = 2 OR logfacility = 3 OR logfacility = 4 Then
isProcessedBln = writeLogFile(thisDateTimeStr, logfacility,subsystem,message)
end if
End Select
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function writeLogFile(timeStamp as String, logfacility as Integer, subsystem as string, message as String) As Boolean
Var LogFile As FolderItem
Var Tos as TextOutputStream
Var LogMessage as String
// FOLDER LOCATION FOR LOG FILE
LogFile = SpecialFolder.UserHome
// LOG MESSAGE STRING CREATION
Var thisTimeStampStr as String = Str(TimeStamp)
Var thisLogFacilityStr as String = Str(logfacility)
LogMessage = formatWriteLogResult(thisTimeStampStr, thisLogFacilityStr, subsystem, message)
if LogFile <> nil AND LogFile.Exists AND LogFile.Directory then
LogFile = SpecialFolder.UserHome.Child(kSystemLogFileDir)
if LogFile <> nil then
if not LogFile.Exists then LogFile.CreateAsFolder
if LogFile.Directory then
LogFile = LogFile.Child(kSystemLogFile)
if LogFile <> nil then
if not LogFile.Directory then
if LogFile.Exists then
Tos = TextOutputStream.append(LogFile)
else
Tos = TextOutputStream.Create(LogFile)
end if
Tos.Write(LogMessage)
Tos.Close
end if
end if
end if
end if
end if
End Function
#tag EndMethod
#tag Property, Flags = &h0
userLogFacilityLevelInt As Integer
#tag EndProperty
#tag Constant, Name = kSystemLogFile, Type = String, Dynamic = False, Default = \"testlogfile.log", Scope = Public
#tag EndConstant
#tag Constant, Name = kSystemLogFileDir, Type = String, Dynamic = False, Default = \"LogFileDir", Scope = Public
#tag EndConstant
#tag ViewBehavior
#tag ViewProperty
Name="Name"
Visible=true
Group="ID"
InitialValue=""
Type="String"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Index"
Visible=true
Group="ID"
InitialValue="-2147483648"
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Super"
Visible=true
Group="ID"
InitialValue=""
Type="String"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Left"
Visible=true
Group="Position"
InitialValue="0"
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Top"
Visible=true
Group="Position"
InitialValue="0"
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="userLogFacilityLevelInt"
Visible=false
Group="Behavior"
InitialValue="4"
Type="Integer"
EditorType="MultiLineEditor"
#tag EndViewProperty
#tag EndViewBehavior
End Module
#tag EndModule