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
+2
View File
@@ -1,6 +1,7 @@
import logging import logging
from logging import Formatter from logging import Formatter
from logging.handlers import RotatingFileHandler, SysLogHandler from logging.handlers import RotatingFileHandler, SysLogHandler
from pathlib import Path
from freqtrade.constants import Config from freqtrade.constants import Config
from freqtrade.exceptions import OperationalException 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")) handler_jd.setFormatter(Formatter("%(name)s - %(levelname)s - %(message)s"))
logging.root.addHandler(handler_jd) logging.root.addHandler(handler_jd)
else: else:
Path(logfile).parent.mkdir(parents=True, exist_ok=True)
handler_rf = get_existing_handlers(RotatingFileHandler) handler_rf = get_existing_handlers(RotatingFileHandler)
if handler_rf: if handler_rf:
logging.root.removeHandler(handler_rf) logging.root.removeHandler(handler_rf)
+1 -1
View File
@@ -86,7 +86,7 @@ def test_set_loggers_Filehandler(tmp_path):
logger = logging.getLogger() logger = logging.getLogger()
orig_handlers = logger.handlers orig_handlers = logger.handlers
logger.handlers = [] logger.handlers = []
logfile = tmp_path / "ft_logfile.log" logfile = tmp_path / "logs/ft_logfile.log"
config = { config = {
"verbosity": 2, "verbosity": 2,
"logfile": str(logfile), "logfile": str(logfile),