OA_Log.bas 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. Option Compare Database
  2. Option Explicit
  3. Dim log_file_path As String
  4. Dim debug_level As Boolean
  5. Private Sub MkLogDir()
  6. Call RecursiveMkDir(Environ("AppData") & "\OpenAccess\log\")
  7. End Sub
  8. Public Function log_dir() As String
  9. log_dir = Environ("AppData") & "\OpenAccess\log\"
  10. End Function
  11. Public Function log_file() As String
  12. log_file = log_file_path
  13. End Function
  14. Public Sub set_debug_mode()
  15. debug_level = True
  16. End Sub
  17. Public Sub set_log_path(ByVal path As String)
  18. Dim FSO As Object
  19. Dim oFile As Object
  20. Set FSO = CreateObject("Scripting.FileSystemObject")
  21. Call MkLogDir
  22. If Not FSO.FileExists(path) Then
  23. Set oFile = FSO.CreateTextFile(path)
  24. oFile.Close
  25. End If
  26. log_file_path = path
  27. End Sub
  28. Public Sub logger(ByVal origin As String, ByVal level As String, ByVal msg As String)
  29. Dim FSO As Object
  30. Dim oFile As Object
  31. Dim Line As String
  32. Dim new_session As Boolean
  33. new_session = False
  34. If level = "DEBUG" And Not debug_level = True Then Exit Sub
  35. Set FSO = CreateObject("Scripting.FileSystemObject")
  36. If Not Len(log_file_path) > 0 Then
  37. log_file_path = log_dir() & "oa_" & Format(Now(), "yymmdd_hhMM") & ".log"
  38. new_session = True
  39. Call set_log_path(log_file_path)
  40. End If
  41. Set oFile = FSO.OpenTextFile(log_file_path, ForAppending)
  42. If new_session Then oFile.WriteLine ("**********************************")
  43. 'oFile.WriteBlankLines (2)
  44. Line = CStr(Now) + " - " + origin + " - " + level + " - " + msg
  45. Debug.Print Line
  46. oFile.WriteLine (Line)
  47. oFile.Close
  48. Set FSO = Nothing
  49. Set oFile = Nothing
  50. If level = "CRITICAL" Then
  51. Call err.Raise(60000, "Critical error", "Critical error occured, see the log file for more informations")
  52. End If
  53. End Sub