Django的记录 - 从处理程序未找到日志文件 [英] Django Logging - Log File from Handler Not Found
问题描述
我在我的Django项目日志记录设置。它的工作原理在当地的发展,但它在生产中造成麻烦。 settings.py
位如下:
I have logging set up in my Django project. It works locally in development but it causing trouble in production. settings.py
bits are as follows:
import os
PROJECT_PATH = os.path.abspath(os.path.dirname(__name__))
. . .
'handlers': {
'log_file': {
'level': 'INFO',
'class': 'logging.handlers.RotatingFileHandler',
'filename': os.path.join(PROJECT_PATH, 'logs/django.log'),
'maxBytes': '16777216',
'formatter': 'verbose'
},
. . .
我不断收到这个错误在 /var/log/apache2/error.log
:
ValueError: Unable to configure handler 'log_file': [Errno 2] No such file or directory: '/logs/django.log'
我已经通过运行code和手动设置 PROJECT_PATH
在Django的外壳测试这一点,它好像又回到了正确的路径。另外,我检查,并检查了权限的日志文件。虽然没有必要,我改成了 777
只是为了测试。仍然没有运气。
I've tested this in the Django shell by running the code and setting PROJECT_PATH
manually and it seems to return the correct path. Plus, I've checked and checked the permissions on the log file. Although unnecessary, I changed it to 777
just to test. Still no luck.
我的本地日志填满了所有我希望同时生产日志为空。
My local log fills up with all that I expect while the production log is empty.
在思考这个问题,我想这日志的位置可能不是最好的,但如果它在生产中工作,至少我知道......然后,我可以在改变位置工作。
In thinking about this, I suppose this log location is probably not the best, but if it worked in production, at least I'd know... Then, I could work on changing the location.
我是什么失踪?
推荐答案
虽然我真的很想得到一个答案,我决定采取另一种办法,所以我可以继续前进。看来这个问题是不是刺激了足够的重视,我不觉得自己像一个赏金,现在,所以我禁用记录到文件现在。我打算无论如何要重新设计我的做法,所以这似乎是一个体面的想法。
Although I would really like to get an answer to this, I have decided to take another approach so I can move on. It seems this question is not spurring enough attention and I don't feel like a bounty right now, so I disabled logging to a file for now. I am going to redesign my approach anyway, so this seems like a decent idea.
我想出了暂时似乎工作,不给错误是这样的(用于文件处理程序定义):
What I came up with temporarily that seems to work and not give errors is this (for the file handler definition):
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': '/some/fixed/path/to/logs/django.log',
},
请注意,我用从衍生os.path.join(PROJECT_PATH,日志/ django.log')值之前
。不知道为什么这没有工作,但它是罪魁祸首。因此,即使该位是正确的: PROJECT_PATH = os.path.abspath是(os.path.dirname(__ __名))
(甚至在蟒蛇壳确认):这不是什么吨的生产工作。
Note that before I was using a value derived from os.path.join(PROJECT_PATH, 'logs/django.log')
. Not sure why this didn't work, but it was the culprit. So even though this bit was correct: PROJECT_PATH = os.path.abspath(os.path.dirname(__name__))
(even confirmed in the python shell), it wasn't working in production.
这篇关于Django的记录 - 从处理程序未找到日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!