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

pull/10831/head
Meng Xiangzhuo 2 years ago
parent 46db0bc08c
commit ba780276a2
No known key found for this signature in database
GPG Key ID: 7A1735AB4A5A3594

@ -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)

@ -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),

Loading…
Cancel
Save