automatically create directory path for logging files (#5249)

This commit is contained in:
Mike Fährmann
2024-02-28 02:11:20 +01:00
parent 24106d9994
commit d921d860f1

View File

@@ -224,6 +224,9 @@ def setup_logging_handler(key, fmt=LOG_FORMAT, lvl=LOG_LEVEL, mode="w"):
try:
path = util.expand_path(path)
handler = logging.FileHandler(path, mode, encoding)
except FileNotFoundError:
os.makedirs(os.path.dirname(path))
handler = logging.FileHandler(path, mode, encoding)
except (OSError, ValueError) as exc:
logging.getLogger("gallery-dl").warning(
"%s: %s", key, exc)