Option Compare Database Option Explicit Dim log_file_path As String Dim debug_level As Boolean Dim p_errors_occured As Boolean Public Function errors_occured() As Boolean errors_occured = p_errors_occured End Function Private Sub MkLogDir() mktree joinpaths(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 If level = "ERROR" Then p_errors_occured = True 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 ("**********************************") 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