简体   繁体   English

为什么我的Django应用程序不能写入其日志文件?

[英]Why can my Django app not write to its log file?

$ sudo /etc/init.d/apache2 restart $ sudo /etc/init.d/apache2 restart

 * Restarting web server apache2  
 ... waiting .   ...done.  

username@servername Thu Nov 04 18:54:37 ~/public_html/IDM_app username @ servername Thu Nov 04 18:54:37~ / public_html / IDM_app
$ sudo tail -n 60 /var/log/apache2/error.log $ sudo tail -n 60 /var/log/apache2/error.log

[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38] mod_wsgi (pid=28760): Exception occurred processing WSGI script '/home/username/public_html/idm.wsgi'.  
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38] Traceback (most recent call last):  
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38]   File "/usr/local/lib/python2.7/site-packages/Django-1.2.3-py2.7.egg/django/core/handlers/wsgi.py", line 230, in __call__  
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38]     self.load_middleware()  
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38]   File "/usr/local/lib/python2.7/site-packages/Django-1.2.3-py2.7.egg/django/core/handlers/base.py", line 33, in load_middleware  
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38]     for middleware_path in settings.MIDDLEWARE_CLASSES:  
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38]   File "/usr/local/lib/python2.7/site-packages/Django-1.2.3-py2.7.egg/django/utils/functional.py", line 276, in __getattr__  
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38]     self._setup()  
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38]   File "/usr/local/lib/python2.7/site-packages/Django-1.2.3-py2.7.egg/django/conf/__init__.py", line 40, in _setup  
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38]     self._wrapped = Settings(settings_module)  
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38]   File "/usr/local/lib/python2.7/site-packages/Django-1.2.3-py2.7.egg/django/conf/__init__.py", line 73, in __init__  
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38]     mod = importlib.import_module(self.SETTINGS_MODULE)  
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38]   File "/usr/local/lib/python2.7/site-packages/Django-1.2.3-py2.7.egg/django/utils/importlib.py", line 35, in import_module  
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38]     __import__(name)  
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38]   File "/home/username/public_html/IDM_app/settings.py", line 60, in <module>  
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38]     from settings_local import *  
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38]   File "/home/username/public_html/IDM_app/settings_local.py", line 1, in <module>  
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38]     from settings_Slicehost_idm import *  
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38]   File "/home/username/public_html/IDM_app/settings_Slicehost_idm.py", line 12, in <module>  
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38]     format='%(pathname)s TIME: %(asctime)s MSG: %(filename)s:%(funcName)s:%(lineno)d %(message)s',  
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38]   File "/usr/local/lib/python2.7/logging/__init__.py", line 1500, in basicConfig  
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38]     hdlr = FileHandler(filename, mode)  
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38]   File "/usr/local/lib/python2.7/logging/__init__.py", line 889, in __init__  
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38]     StreamHandler.__init__(self, self._open())  
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38]   File "/usr/local/lib/python2.7/logging/__init__.py", line 908, in _open  
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38]     stream = open(self.baseFilename, self.mode)  
[Thu Nov 04 18:54:27 2010] [error] [client 8.17.58.38] IOError: [Errno 13] Permission denied: '/home/username/public_html/IDM_app/log/django.osqa.log'  
[Thu Nov 04 18:54:36 2010] [notice] caught SIGTERM, shutting down  
[Thu Nov 04 18:54:37 2010] [notice] Apache/2.2.14 (Ubuntu) mod_wsgi/3.3 Python/2.7 configured -- resuming normal operations  

username@servername Thu Nov 04 18:54:42 ~/public_html/IDM_app username @ servername Thu Nov 04 18:54:42~ / public_html / IDM_app
$ ls -l /home/username/public_html/IDM_app/log/django.osqa.log $ ls -l /home/username/public_html/IDM_app/log/django.osqa.log

-rw-r--r-- 1 username 0 Nov  4 18:24 /home/username/public_html/IDM_app/log/django.osqa.log  

username@servername Thu Nov 04 19:08:41 ~/public_html/IDM_app username @ servername Thu Nov 04 19:08:41~ / public_html / IDM_app
**$ ls -l ~/public_html/idm.wsgi ** ** $ ls -l~ / public_html / idm.wsgi **

-rw-r--r-- 1 username 222 Nov  4 18:53 /home/username/public_html/idm.wsgi  

username@servername Thu Nov 04 19:10:50 ~/public_html/IDM_app username @ servername Thu Nov 04 19:10:50~ / public_html / IDM_app
$ cat ~/public_html/idm.wsgi $ cat~ / public_html / idm.wsgi

import os
import sys

sys.path.append('/home/username/public_html/IDM_app/')

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

username@servername Thu Nov 04 19:11:02 ~/public_html/IDM_app $ whoami username @ servername Thu Nov 04 19:11:02~ / public_html / IDM_app $ whoami

username

If Apache2 uses the Virtual Host setup file @ ~/public_html/idm.wsgi, what User does the system think is trying to write the the log file log/django.osqa.log ? 如果Apache2使用虚拟主机设置文件@~ / public_html / idm.wsgi,那么系统认为用户在尝试编写日志文件log / django.osqa.log?

Why can my Django app not write to its log file? 为什么我的Django应用程序不能写入其日志文件?

Apache's probably running as the apache user, meaning that it doesn't have write access to the log file. Apache可能作为apache用户运行,这意味着它没有对日志文件的写访问权。 It starts up fine because it only has to read the wsgi file, which has read permissions for all users. 它启动很好,因为它只需要读取wsgi文件,该文件具有所有用户的读取权限。 either chmod a+w django.osqa.log or chown <apache-user> django.osqa.log . chmod a+w django.osqa.logchown <apache-user> django.osqa.log

Note: the preferred method would be to chown the file. 注意:首选方法是chown文件。

Note 2: this is distro-dependent, but since that looks Ubuntu-y, the apache user will be www-data . 注2:这是依赖于发行版的,但由于它看起来像Ubuntu-y,因此apache用户将是www-data

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 python 中,我可以将日志写入控制台,但没有写入文件 - In python I can write a log to console but its not getting written into file Django应用日志级别信息未写入文件 - Django App Log level info not getting write into file 带有Django的apache2-无法写入日志文件 - apache2 with django - can't write to log file 为什么我无法使用有效凭据登录 Django 用户,但可以登录我原来的超级用户? - Why can't I log into Django users with valid credentials, but can log into my original superuser? Django我们如何使用应用程序名称目录和Todaydate.log文件生成应用程序明智日志 - Django How can we generate app wise log with app name directory and todaydate.log file Django部署的应用程序/项目无法写入文件 - Django deployed app/project can't write to a file 为什么我的 Django 应用程序无法在视图中找到我的 function? - Why can't my Django app find my function in views? 当控制台日志不存在时,为什么我的Python Django日志记录文件为空? - Why is my Python Django logging file empty when my console log is not? Python:为什么我的程序无法从列表写入文件? - Python: Why can't my program write to a file from a list? 我能够在 heroku 上构建我的 django web 应用程序,但在启动时显示这些错误(错误日志如下所示) - i am able to build my django web app on heroku but while launching its showing these error(error log shown below)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM