VBMAN.Logs - Log Recording Object
Overview
VBMAN.Logs provides multi-channel log recording functionality, supporting file logs, form display, web remote debugging and other output methods.
Core Features
- Multi-channel Output: File, form, DbgView, web remote debugging
- Log Levels: Supports multiple log level controls
- Async Submission: Network logs use async method, non-blocking
- Log Viewer: Built-in log viewer form
Log Level Enum
vb
Public Enum EnumLogLevel
LvInfo = 0 ' Information
LvWarn = 1 ' Warning
LvDanger = 2 ' Danger
LvError = 3 ' Error
LvDebugger = 4 ' Debug
LvCustom = 5 ' Custom
End EnumLog Filename Rule Enum
vb
Public Enum EnumLogFileNameRule
None = 0 ' No rule
ByMonth = 1 ' By month
ByDay = 2 ' By day
byUser = 3 ' User custom
End EnumProperties
| Property | Type | Description |
|---|---|---|
LogLevelControl | EnumLogLevel | Current log control level |
SendToFormView | Boolean | Whether to output to form |
SendToDbgView | Boolean | Whether to output to DbgView |
SendToWebView | Boolean | Whether to output to web |
FormListBox | VB.ListBox | ListBox control to output to |
FormListBoxMaxItem | Long | Maximum number of items in ListBox |
LogDir | String | Log file root directory |
LogSubDir | String | Log subdirectory |
LogFileNameRule | EnumLogFileNameRule | Log filename rule |
LogFileNameByUer | String | User custom filename |
WebUserCode | String | Web debug user identification code |
ShowLogsViewer | Boolean | Whether log viewer is shown (read/write) |
LastError | String | Last error message |
Methods
HostApp
Set host application (chain calling)
vb
Public Function HostApp(o As Object) As cLogsView
Set log viewer display state (chain calling)
vb
Public Function View(Value As Boolean) As cLogsData
Add log data (chain calling)
vb
Public Function Data(ByVal LogContent As String, Optional ByVal LogTitle As String, Optional LogLevel As EnumLogLevel = LvInfo) As cLogsExample:
vb
VBMAN.Logs.Data("User login successful", "Login Module", LvInfo)DataLine
Add log data with newline (chain calling)
vb
Public Function DataLine(ByVal LogContent As String, Optional ByVal LogTitle As String, Optional LogLevel As EnumLogLevel = LvInfo) As cLogsExample:
vb
VBMAN.Logs.DataLine "Operation completed" & vbCrLf & "Result: Success", "Business Module", LvInfoToFormView
Output to form ListBox
vb
Public Function ToFormView(LogStr As String, Optional LogLevel As EnumLogLevel) As StringToWebView
Output to web remote debugging
vb
Public Function ToWebView(LogStr As String, Optional LogLevel As EnumLogLevel) As StringComprehensive Examples
Example 1: Basic Log Recording
vb
Private Sub TestLog()
' Simple log
VBMAN.Logs.Data "Program started", "System", LvInfo
' Log with title and level
VBMAN.Logs.Data "Disk space insufficient", "Monitor", LvWarn
' Multi-line log
VBMAN.Logs.DataLine "Error occurred" & vbCrLf & Err.Description, "Error Handling", LvError
End SubExample 2: Chain Calling
vb
Private Sub ChainLog()
VBMAN.Logs _
.HostApp(Me) _
.View(True) _
.Data("Initialization completed", "Startup", LvInfo) _
.Data("Loading configuration", "Config", LvInfo) _
.DataLine "Configuration loading completed", "Config", LvInfo
End SubExample 3: Output to Form Control
vb
Private Sub Form_Load()
' Set output to List1 control
Set VBMAN.Logs.FormListBox = List1
VBMAN.Logs.FormListBoxMaxItem = 500
VBMAN.Logs.SendToFormView = True
End Sub
Private Sub DoSomething()
VBMAN.Logs.Data "Processing...", "Business", LvInfo
' ... processing logic
VBMAN.Logs.Data "Processing completed", "Business", LvInfo
End SubExample 4: Web Remote Debugging
vb
Private Sub SetupWebLog()
' Set web debug user code (register at http://log.vb6.pro)
VBMAN.Logs.WebUserCode = "myapp123"
VBMAN.Logs.SendToWebView = True
End Sub
Private Sub RemoteLog()
VBMAN.Logs.ToWebView "Remote debug info", LvInfo
End SubExample 5: Open Log Viewer
vb
Private Sub ShowLogViewer()
VBMAN.Logs.ShowLogsViewer = True
' Or
VBMAN.Logs.View(True)
End SubBest Practices
- Log Level Control: Set appropriate LogLevelControl based on environment
- Async Network Logs: Web debugging uses async submission, does not affect performance
- Log Cleanup: Regularly clean up old log files
- Sensitive Information: Don't record passwords and other sensitive information in logs
- Error Handling: Log recording failure should not affect main program operation