简体   繁体   中英

How can I specify a relative path in a Python logging config file?

I've the following file to config logging:

[loggers]
keys=root

[handlers]
keys = root

[formatters]
keys = generic

# Loggers
[logger_root]
level = DEBUG
handlers = root

# Handlers
[handler_root]
class = handlers.RotatingFileHandler
args = ("test.log", "maxBytes=1*1024*1024", "backupCount=10")
level = NOTSET
formatter = generic

# Formatters
[formatter_generic]
format = %(asctime)s,%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %Y-%m-%d %H:%M:%S

In Development this works great, but when I deploy the application test.log is trying to be written in a path in which I don't have the necessary permission.

So my question is, How can I do to specify a relative path in this configuration 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM