backtrader.utils.log_message module

Log Message Module - Logging utilities for backtrader.

This module provides a unified logging interface using the Python standard logging module. It supports file logging with daily rotation and optional console output.

The SpdLogManager class is kept for backward compatibility but now wraps logging.getLogger internally instead of requiring the third-party spdlog package.

Classes:

SpdLogManager: Logger factory (stdlib logging under the hood).

Example

>>> log_manager = SpdLogManager(file_name="mylog.log")
>>> logger = log_manager.create_logger()
>>> logger.info("Strategy started")
class backtrader.utils.log_message.SpdLogManager[source]

Bases: object

Logger factory using the Python standard logging module.

Creates loggers with daily file rotation and optional console output. API is kept compatible with the previous spdlog-based implementation.

file_name

Name of the log file.

logger_name

Name for the logger.

rotation_hour

Hour of day for log rotation (0-23).

rotation_minute

Minute of hour for log rotation (0-59).

print_info

Whether to also print to console.

__init__(file_name='log_strategy_info.log', logger_name='hello', rotation_hour=0, rotation_minute=0, print_info=False)[source]

Initialize the SpdLogManager.

Parameters:
  • file_name – Name of the output log file.

  • logger_name – Name for the logger.

  • rotation_hour – Hour (0-23) to rotate log files daily.

  • rotation_minute – Minute (0-59) to rotate log files.

  • print_info – Whether to also output to console.

create_logger()[source]

Create and return a configured logging.Logger instance.

Returns:

Logger with file handler (daily rotation) and optionally a console handler.

Return type:

logging.Logger