backtrader.utils.log_message module¶
Log Message Module - Logging utilities for backtrader.
This module provides logging functionality using spdlog if available, with a fallback to simple console logging. It supports daily log file rotation and configurable output sinks.
- Classes:
SpdLogManager: Manager for creating spdlog-based loggers. SimpleLogger: Fallback logger that prints to console. DummyLogger: Dummy logger used when spdlog is not available. DummySpdLog: Dummy spdlog module for import fallback.
示例
>>> log_manager = SpdLogManager(file_name="mylog.log")
>>> logger = log_manager.create_logger()
>>> logger.info("Strategy started")
- class backtrader.utils.log_message.SpdLogManager[源代码]¶
基类:
objectManager for creating spdlog-based loggers.
Creates loggers with daily file rotation. Requires the spdlog package to be installed. Falls back to console logging if spdlog is unavailable.
- 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.
- spdlog_available¶
Whether spdlog is installed.
- __init__(file_name='log_strategy_info.log', logger_name='hello', rotation_hour=0, rotation_minute=0, print_info=False)[源代码]¶
Initialize the SpdLogManager.
- 参数:
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.
- class backtrader.utils.log_message.DummySpdLog[源代码]¶
基类:
objectDummy spdlog module for when spdlog is not installed.
Provides stub implementations of spdlog functions to prevent import errors when the spdlog package is not available.
- static SinkLogger(name, sinks)[源代码]¶
Create a dummy logger.
- 参数:
name -- Logger name.
sinks -- List of sinks (ignored).
- 返回:
A logger that prints to console.
- 返回类型:
DummyLogger