I would like to use python's logging framework in my application, and I'd like to allow the end user of my application to specify the log file. (Via the Python logging framework's configuration mechanisms which in my case is a section of a YAML file that the end user can edit to specify how logging behaves.)
Is there a way to get the logging framework to ensure that a directory exists by creating it? Because the exact path to the logging filename is embedded in the configuration information specified by the end user, it is nontrivial for me as the application writer to parse this information to determine which directory should be created.
If the end user specifies "foo/bar/baz.log", I would like to make sure that the foo/bar directory is created.
Note: This is the Python equivalent of this SO question about Java logging.
Subclass
FileHandler
(or whatever handler you are using) to callmkdir_p
during initialization: