| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- Option Compare Database
- Option Explicit
- Dim log_file_path As String
- Dim debug_level As Boolean
- Private Sub MkLogDir()
- Call RecursiveMkDir(Environ("AppData") & "\OpenAccess\log\")
- End Sub
- Public Function log_dir() As String
- log_dir = Environ("AppData") & "\OpenAccess\log\"
- End Function
- Public Function log_file() As String
- log_file = log_file_path
- End Function
- Public Sub set_debug_mode()
- debug_level = True
- End Sub
- Public Sub set_log_path(ByVal path As String)
- Dim FSO As Object
- Dim oFile As Object
-
- Set FSO = CreateObject("Scripting.FileSystemObject")
-
- Call MkLogDir
-
- If Not FSO.FileExists(path) Then
- Set oFile = FSO.CreateTextFile(path)
- oFile.Close
- End If
-
- log_file_path = path
-
- End Sub
- Public Sub logger(ByVal origin As String, ByVal level As String, ByVal msg As String)
- Dim FSO As Object
- Dim oFile As Object
- Dim Line As String
- Dim new_session As Boolean
- new_session = False
-
- If level = "DEBUG" And Not debug_level = True Then Exit Sub
- Set FSO = CreateObject("Scripting.FileSystemObject")
- If Not Len(log_file_path) > 0 Then
- log_file_path = log_dir() & "oa_" & Format(Now(), "yymmdd_hhMM") & ".log"
- new_session = True
- Call set_log_path(log_file_path)
- End If
- Set oFile = FSO.OpenTextFile(log_file_path, ForAppending)
- If new_session Then oFile.WriteLine ("**********************************")
- 'oFile.WriteBlankLines (2)
- Line = CStr(Now) + " - " + origin + " - " + level + " - " + msg
- Debug.Print Line
- oFile.WriteLine (Line)
- oFile.Close
- Set FSO = Nothing
- Set oFile = Nothing
-
- If level = "CRITICAL" Then
- Call err.Raise(60000, "Critical error", "Critical error occured, see the log file for more informations")
- End If
-
- End Sub
|