|
1 | 1 | import logging
|
2 | 2 | from logging import Formatter
|
3 | 3 | from logging.handlers import RotatingFileHandler, SysLogHandler
|
| 4 | +from pathlib import Path |
4 | 5 |
|
5 | 6 | from freqtrade.constants import Config
|
6 | 7 | from freqtrade.exceptions import OperationalException
|
@@ -86,11 +87,23 @@ def setup_logging(config: Config) -> None:
|
86 | 87 | handler_rf = get_existing_handlers(RotatingFileHandler)
|
87 | 88 | if handler_rf:
|
88 | 89 | logging.root.removeHandler(handler_rf)
|
89 |
| - handler_rf = RotatingFileHandler( |
90 |
| - logfile, |
91 |
| - maxBytes=1024 * 1024 * 10, # 10Mb |
92 |
| - backupCount=10, |
93 |
| - ) |
| 90 | + try: |
| 91 | + logfile_path = Path(logfile) |
| 92 | + logfile_path.parent.mkdir(parents=True, exist_ok=True) |
| 93 | + handler_rf = RotatingFileHandler( |
| 94 | + logfile_path, |
| 95 | + maxBytes=1024 * 1024 * 10, # 10Mb |
| 96 | + backupCount=10, |
| 97 | + ) |
| 98 | + except PermissionError: |
| 99 | + raise OperationalException( |
| 100 | + f'Failed to create or access log file "{logfile_path.absolute()}". ' |
| 101 | + "Please make sure you have the write permission to the log file or its parent " |
| 102 | + "directories. If you're running freqtrade using docker, you see this error " |
| 103 | + "message probably because you've logged in as the root user, please switch to " |
| 104 | + "non-root user, delete and recreate the directories you need, and then try " |
| 105 | + "again." |
| 106 | + ) |
94 | 107 | handler_rf.setFormatter(Formatter(LOGFORMAT))
|
95 | 108 | logging.root.addHandler(handler_rf)
|
96 | 109 |
|
|
0 commit comments