Skip to content

Commit

Permalink
feat(logging): logging kwargs get passed to strategy instances
Browse files Browse the repository at this point in the history
  • Loading branch information
kieran-mackle committed Mar 20, 2024
1 parent fe8ed6c commit 886e3ca
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions autotrader/autobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def __init__(
"instrument": self.instrument,
"broker": self._broker,
"notifier": self._notifier,
"logger_kwargs": self._logger_kwargs,
}

# Instantiate Strategy
Expand Down
5 changes: 5 additions & 0 deletions autotrader/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init__(
instrument: str,
broker: Broker,
notifier: Notifier,
logger_kwargs: dict[str, any],
*args,
**kwargs
) -> None:
Expand All @@ -36,6 +37,10 @@ def __init__(
notifier : Notifier | None
The notifier object. If notify is not set > 0, then this will be a NoneType object.
logger_kwargs : dict[str, any]
The logger configuration for this instance of AutoTrader. This can be unpacked
into the get_logger() utility function when creating strategy loggers.
"""
super().__init__()

Expand Down
2 changes: 1 addition & 1 deletion autotrader/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def get_logger(
# Check log directory exists
if not os.path.exists(log_dir):
os.mkdir(log_dir)
logfile_path = os.path.join(log_dir, f"{name}.log")
logfile_path = os.path.join(log_dir, f"{name.replace(os.sep, '_')}.log")
fh = logging.FileHandler(logfile_path, mode="a")
fh.setLevel(file_level)
fh.setFormatter(logging.Formatter(CustomLoggingFormatter.default_fmt))
Expand Down

0 comments on commit 886e3ca

Please sign in to comment.