Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

group.start_log() failing if no directory exists. #29

Open
daverolli opened this issue Nov 18, 2019 · 3 comments
Open

group.start_log() failing if no directory exists. #29

daverolli opened this issue Nov 18, 2019 · 3 comments

Comments

@daverolli
Copy link
Contributor

If you run group.start_log('logs') to start logging but the directory logs doesn't exist, it returns None and fails to start logging. Expected behaviors might be:

  • Create the directory if it doesn't exist
  • Keep running but print a warning that the directory doesn't exist and that logging isn't happening. In this case it would be good if the various examples could include logs sub-folders so all the code works out of the box
  • Throw an error telling the user to make the logs directory.
@daverolli daverolli changed the title group.start_log() failing if no directory exists. group.start_log() failing if no directory exists. Nov 18, 2019
@rLinks234
Copy link
Contributor

Next release will raise an exception if the log file could not be created (None is returned).

Additionally, in the event which you're talking about (group.start_log(your_directory)), the error message will be descriptive to the user, telling them why an exception was raised. It will look like:

OSError: Could not start logging because directory '{your_directory_here}' does not exist and 'mkdirs=False'

To create the directory (or directories), there is a new flag added: mkdirs.

For now, mkdirs is False by default, which keeps the behavior you're seeing (whether or not that is a convenient behavior), but it's subject to change in a future release.


So, to get the behavior where your directory will be created for you (if it doesn't exist), you will just change your code from

log_file_path = group.start_log('logs')

to

log_file_path = group.start_log('logs', mkdirs=True)

@ennerf
Copy link

ennerf commented Dec 2, 2019

I'd probably vote for defaulting mkdirs to true. Is there a use case for someone not wanting to create the directory if it doesn't exist?

@rLinks234
Copy link
Contributor

mkdirs made its way into the 2.x.y API set to False by default. This is more cumbersome to the user, if they would want the directory to be made for them, but an exception will be raised if the directory does not exist. A useful error message will also be printed out. I think this discussion is moot, but I do personally think it is at least a sufficient argument to say that we shouldn't create directories on the user's device by default.

However, the examples are currently being overhauled to use

log_file_path = group.start_log('logs', mkdirs=True)

everywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants