VBA Monologger - Log smarter, debug faster !

VBA Monologger is an advanced and flexible logging open-source solution for VBA (Visual Basic for Applications) ecosystem. Easily send logs to the Excel console (Immediate Windows), or simultaneously to a file, or even in a Windows console. Set up in two minutes.

Get started   Learn more

Severity log levels

Manages 8 standard severity levels to classify the importance of log messages, following the PSR-3 standard. It indicates the severity of each event, from the most trivial to the most catastrophic, and allow administrators or developers to filter messages based on their importance.

Logging format

Specify the logging format to define how log messages are structured and displayed. This can be represented on one or multiple lines, with or without ANSI color support, in JSON format, or any other format such as an HTML content.

Multiples logs destinations

Specify the destination where logs should be sent, whether it be the VBA console (Excel's immediate window), the Windows console (cmd.exe), or in a file. Additionally, configure the conditions under which logging events are triggered based on specific criteria.

Enrich log records

Enhance log records using pre-processors to add context, transform data, or customize log entries to meet specific requirements. Examples include adding CPU or memory usage, generating a unique identifier for each session, or adding tags and more.

Advanced usages

Create your own custom logging system and manage log propagation (bubbling) when multiple destinations are used. Use channels to identify which part of an application a log entry is associated with. Use dependency injection for logging capabilities within a custom class module.

Customize

Easily develop your own formatter, handler, and pre-processors to tailor the logging system to your specific needs. By creating unique formatting styles, specialized handlers, and custom pre-processing logic, you can enhance the functionality and flexibility of your logging system.

8 severity log levels

Easily create a logger for ouputting logs into the VBA console with the factory pattern. You have 8 methods, one for each log severity level.

Public Sub howto_use_logger_console_VBA()
    Dim Logger As VBAMonologger.LoggerInterface
    Set Logger = VBAMonologger.Factory.createLoggerConsoleVBA()

    ' Use the logger for each severity levels
    Logger.trace "Authentication function call for user 'Bob Morane'." 
    Logger.info "User 'UltraVomit' has logged in successfully."
    Logger.notice "Process completed successfully with minor issues."
    Logger.warning "'Beetlejuice' should not be called more than 3 times."
    Logger.error "An error occurred with the user 'DRZCFOS2'."
    Logger.critical "System is in an unstable state."
    Logger.alert "Action required: unable to generate the dashboard."
    Logger.emergency "A critical failure occurred in the application."
End Sub

Learn more

Redirect logs to the Windows console or save them to a file

If you prefer, you can display your VBA logs outside the Microsoft Excel by outputting them directly to the Windows Console (cmd.exe), with or without ANSI color support. You can also customize the color scheme based on the log level.

And simultaneously, you can also write log entries to one or multiple files: for example a specific file for errors and another for debugging.

Learn more

Add context data into log message

In addition to the basic log message, you may sometimes want to include extra data that helps to provide more context for the event being logged. You can give a variable context with log message. It is a simply VBA dictionary, where you can store key-value pairs that hold relevant information. When you create a log entry, this context can be attached and will be incorporated into the log output, providing deeper insights into the logged event.

This variable can simply be displayed (or not) into the log message, or can be consumed by using placeholders in log message.

Learn more

' Set context 
Dim context As Object: Set context = CreateObject("Scripting.Dictionary")
context.Add "Username", "v20100v"

' Only display log context (if configuration's formatter allow to show it)
Logger.info "Adding a new user", context

' Consume log context with placeholder
Logger.info "Adding the new user: '{username}'", context
Result
[2024-11-05 09:15:34] app.INFO: Adding a new user | {"Username": "v20100v"}[2024-11-05 09:15:34] app.INFO: Adding the new user: 'v20100v' | {"Username": "v20100v"}
[2024/12/13 18:59:30] App.INFO: User '35353' has logged in successfully.
 | extra:
 | {
 |    "session-UID": "A09A248CF0",
 |    "memory": {
 |       "memory-used": "65%",
 |       "memory-total": "15,23",
 |       "memory-available": "5,30"
 |    },
 |    "CPU-used": "21,4%"
 | }

Enrich log records with pre-processors

Pre-processors are a powerful feature, allowing for additional metadatas to be added to log messages before they are recorded. These functions can be used to enrich log messages with extra information that might not be directly part of the log entry itself, but is still relevant for better understanding and tracking.

Pre-processors can modify, format, or even generate additional metadata that can be attached to each log message into the extra property, for example to add a session ID, one or more tags, the CPU usage, the memory usage and more.

Learn more

Buy me a coffee

Want to support me? Offer me a coffee!

VBA Monologger is fully free and open source under the MIT License, but if you want to support me, you can offer me a coffee here or by scanning this QR code. Thank you in advance for your assistance and your appreciation ^^.

Want to contribute?

Ideas, bug reports, reports a typo in documentation, comments and suggestions, pull-request & Github stars are always welcome on VBA Monologger repository.