Skip to content
Lasse27 edited this page Mar 10, 2025 · 2 revisions

Package content:

  • Configurable Log Levels: Supports DEBUG, INFO, WARNING, and CRITICAL levels.
  • Dynamic Scopes: Easily set and clear logging contexts for more granular control.
  • Flexible Formatting: Customize log output with template-based, token-driven formatting.
  • Dual Logging Outputs: Log messages can be sent to both the console and files (append mode).
  • High Throughput: Capable of handling approximately 3000 log messages per second.

Usage Examples

Simple logger without any configuration:

Prints the standard format to the console, doesn't print to file and uses the standard time formatting.

The message at level DEBUG is not printed out, since the minimum level is INFO by default:

from fusion_logger_python import *

if __name__ == "__main__":
    # Build and configure the logger
    logger: FusionLogger = FusionLoggerBuilder().build()

    # Log messages at different levels
    logger.debug("This is a debug message.")
    logger.info("This is an info message.")
    logger.warning("This is a warning message.")
    logger.critical("This is a critical error message.")

Output:

[INFO] 2025-03-10 12:47:02 [FusionLogger] This is an info message.
[WARN] 2025-03-10 12:47:02 [FusionLogger] This is a warning message.
[CRIT] 2025-03-10 12:47:02 [FusionLogger] This is a critical error message.

Logger with configuration and usage of scopes:

Prints with the specified format to the console. Minimum level is DEBUG, therefore all messages get displayed. Since name isn't specified in the logformat, it is ignored in the output.

if __name__ == "__main__":
    # Build and configure the logger
    formatter: FusionLogFormatter = FusionLogFormatter("[{LEVEL}] {TIMESTAMP} | {HOSTNAME} {SCOPE} | {MESSAGE}")
    logger: FusionLogger = FusionLoggerBuilder() \
        .set_formatter(formatter) \
        .set_name("SampleLogger") \
        .set_min_level(FusionLogLevel.DEBUG) \
        .build()

    # Log messages at different levels
    logger.debug("This is a debug message.")
    logger.info("This is an info message.")

    logger.begin_scope("SampleScope")
    logger.debug("This is a debug message.")
    logger.info("This is an info message.")
    logger.warning("This is a warning message.")
    logger.critical("This is a critical error message.")
    logger.end_scope("SampleScope")

    logger.debug("This is a debug message.")
    logger.info("This is an info message.")

Output

[DEBU] 2025-03-10 12:52:45 | DESKTOP-XXXXXXX  | This is a debug message.
[INFO] 2025-03-10 12:52:45 | DESKTOP-XXXXXXX  | This is an info message.
[DEBU] 2025-03-10 12:52:45 | DESKTOP-XXXXXXX SampleScope | This is a debug message.
[INFO] 2025-03-10 12:52:45 | DESKTOP-XXXXXXX SampleScope | This is an info message.
[WARN] 2025-03-10 12:52:45 | DESKTOP-XXXXXXX SampleScope | This is a warning message.
[CRIT] 2025-03-10 12:52:45 | DESKTOP-XXXXXXX SampleScope | This is a critical error message.
[DEBU] 2025-03-10 12:52:45 | DESKTOP-XXXXXXX | This is a debug message.
[INFO] 2025-03-10 12:52:45 | DESKTOP-XXXXXXX | This is an info message.

Clone this wiki locally