Skip to content

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 Enum

Log Filename Rule Enum

vb
Public Enum EnumLogFileNameRule
    None = 0        ' No rule
    ByMonth = 1     ' By month
    ByDay = 2       ' By day
    byUser = 3      ' User custom
End Enum

Properties

PropertyTypeDescription
LogLevelControlEnumLogLevelCurrent log control level
SendToFormViewBooleanWhether to output to form
SendToDbgViewBooleanWhether to output to DbgView
SendToWebViewBooleanWhether to output to web
FormListBoxVB.ListBoxListBox control to output to
FormListBoxMaxItemLongMaximum number of items in ListBox
LogDirStringLog file root directory
LogSubDirStringLog subdirectory
LogFileNameRuleEnumLogFileNameRuleLog filename rule
LogFileNameByUerStringUser custom filename
WebUserCodeStringWeb debug user identification code
ShowLogsViewerBooleanWhether log viewer is shown (read/write)
LastErrorStringLast error message

Methods

HostApp

Set host application (chain calling)

vb
Public Function HostApp(o As Object) As cLogs

View

Set log viewer display state (chain calling)

vb
Public Function View(Value As Boolean) As cLogs

Data

Add log data (chain calling)

vb
Public Function Data(ByVal LogContent As String, Optional ByVal LogTitle As String, Optional LogLevel As EnumLogLevel = LvInfo) As cLogs

Example:

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 cLogs

Example:

vb
VBMAN.Logs.DataLine "Operation completed" & vbCrLf & "Result: Success", "Business Module", LvInfo

ToFormView

Output to form ListBox

vb
Public Function ToFormView(LogStr As String, Optional LogLevel As EnumLogLevel) As String

ToWebView

Output to web remote debugging

vb
Public Function ToWebView(LogStr As String, Optional LogLevel As EnumLogLevel) As String

Comprehensive 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 Sub

Example 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 Sub

Example 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 Sub

Example 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 Sub

Example 5: Open Log Viewer

vb
Private Sub ShowLogViewer()
    VBMAN.Logs.ShowLogsViewer = True
    ' Or
    VBMAN.Logs.View(True)
End Sub

Best Practices

  1. Log Level Control: Set appropriate LogLevelControl based on environment
  2. Async Network Logs: Web debugging uses async submission, does not affect performance
  3. Log Cleanup: Regularly clean up old log files
  4. Sensitive Information: Don't record passwords and other sensitive information in logs
  5. Error Handling: Log recording failure should not affect main program operation

VB6 and LOGO copyright of Microsoft Corporation