feat: auto-create logs dir if it's absent

This commit is contained in:
Meng Xiangzhuo
2024-10-23 00:22:23 +08:00
parent 46db0bc08c
commit ba780276a2
2 changed files with 3 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
import logging
from logging import Formatter
from logging.handlers import RotatingFileHandler, SysLogHandler
from pathlib import Path
from freqtrade.constants import Config
from freqtrade.exceptions import OperationalException
@@ -83,6 +84,7 @@ def setup_logging(config: Config) -> None:
handler_jd.setFormatter(Formatter("%(name)s - %(levelname)s - %(message)s"))
logging.root.addHandler(handler_jd)
else:
Path(logfile).parent.mkdir(parents=True, exist_ok=True)
handler_rf = get_existing_handlers(RotatingFileHandler)
if handler_rf:
logging.root.removeHandler(handler_rf)

View File

@@ -86,7 +86,7 @@ def test_set_loggers_Filehandler(tmp_path):
logger = logging.getLogger()
orig_handlers = logger.handlers
logger.handlers = []
logfile = tmp_path / "ft_logfile.log"
logfile = tmp_path / "logs/ft_logfile.log"
config = {
"verbosity": 2,
"logfile": str(logfile),