VCS_Log.bas 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. Option Compare Database
  2. Dim log_file_path As String
  3. Dim debug_level As Boolean
  4. Public Function log_file()
  5. log_file = log_file_path
  6. End Function
  7. Public Sub set_debug_mode()
  8. debug_level = True
  9. End Sub
  10. Public Sub logger(ByVal origin As String, ByVal level As String, ByVal msg As String)
  11. Dim fso As Object
  12. Dim oFile As Object
  13. Dim line As String
  14. Dim new_session As Boolean
  15. new_session = False
  16. If level = "DEBUG" And Not debug_level = True Then Exit Sub
  17. Set fso = CreateObject("Scripting.FileSystemObject")
  18. If Not Len(log_file_path) > 0 Then
  19. log_file_path = CurrentProject.path & "\" & "VCS.log"
  20. Debug.Print log_file_path
  21. new_session = True
  22. If Not fso.FileExists(log_file_path) Then
  23. Set oFile = fso.CreateTextFile(log_file_path)
  24. oFile.Close
  25. End If
  26. End If
  27. Set oFile = fso.OpenTextFile(log_file_path, ForAppending)
  28. If new_session Then oFile.WriteLine ("**********************************")
  29. 'oFile.WriteBlankLines (2)
  30. line = CStr(Now) + " - " + origin + " - " + level + " - " + msg
  31. Debug.Print line
  32. oFile.WriteLine (line)
  33. oFile.Close
  34. Set fso = Nothing
  35. Set oFile = Nothing
  36. If level = "CRITICAL" Then
  37. Call err.Raise(60000, "Critical error", "Critical error occured, see the log file for more informations")
  38. End If
  39. End Sub