开发者

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 %(lev开发者_高级运维elname)-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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜