[Solved]-How can I specify a relative path in a Python logging config file?


Mark is right, your path in the config file is relative to whatever directory is current when the logging.config.fileConfig call is made. This depends on the details of your deployment method.

You may need to specify an absolute path to your file, by prefixing ‘test.log’ with a directory you know to be writable by the process running your code.

Another problem might just be a permissions issue with the user your Django process runs under: typically when running the development server it runs under your account and you will typically not encounter permissions issues. When deploying (with Apache and mod_wsgi, say) the Apache process and/or mod_wsgi daemon process run under different accounts which may need to be given permission to the relevant folder.

If you need more help, please give more details about your deployment with respect to the method, location of log file directory etc.


Just consolidate a little bit, the log file specifying in the configuration actually is relative to where you run your program. For example, when I deploy my apache server running at root file "/path/to/root". The log config you specify will try to write at "/path/to/root/test.log"

Look further at this thread: Using program variables in python logging configuration file


Leave a comment