Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

[RFE] - Create directory structure, if it doesn't exist #129

Open
JacobCallahan opened this issue Aug 30, 2018 · 0 comments · May be fixed by #432
Open

[RFE] - Create directory structure, if it doesn't exist #129

JacobCallahan opened this issue Aug 30, 2018 · 0 comments · May be fixed by #432

Comments

@JacobCallahan
Copy link

  • logzero version: 1.5.0
  • Python version: 3.6.6
  • Operating System: Fedora 28

Description

When passing in a log path, that doesn't exist, logzero will fail with a FileNotFoundError.
Instead, logzero should attempt to create the parent directories.

What I Did

tried to pass a relative path logs/clix.log to the logzero.logfile method. since logs didn't yet exist, the method failed with:

...
File "/usr/lib64/python3.6/logging/__init__.py", line 1060, in _open
    return open(self.baseFilename, self.mode, encoding=self.encoding)
FileNotFoundError: [Errno 2] No such file or directory: '/home/jake/Programming/clix/logs/clix.log'

Workaround

Add two lines to whatever file you use to init logzero. I believe this requires python 3.5+. You can always use os to do the same thing on older versions of python.

from pathlib import Path
...
Path(log_path).parent.mkdir(parents=True, exist_ok=True)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant