Django Logging To Apache Error Log
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings apache error logging level and policies of this site About Us Learn more about Stack
Django Console Log
Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs apache startup log Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; php error logging it only takes a minute: Sign up How to debug django with logging on Apache? up vote 1 down vote favorite I have deployed my django site on Apache and there's a problem which did not occur on my development machine, so I want to print some variables out to see what is happening. I tried to use python logging
Mysql Error Logging
module, where I did this: import os, logging FILE = os.getcwd() logging.basicConfig(filename=os.path.join(FILE,'log.txt'),level=logging.DEBUG) logging.debug('Write') On my development machine there could be a log.txt showing up in the root directory in my django project. However when I did the same thing, there is not log.txt file showing up in the corresponding directory on my server. Does anyone know how to debug it? Thanks! python django apache django-debug-toolbar share|improve this question asked Mar 18 '14 at 5:12 Robert 5213828 Mmm. check permission of directory where your log file is storing . –Priyank Patel Mar 18 '14 at 5:13 add a comment| 3 Answers 3 active oldest votes up vote 0 down vote accepted You're assuming the current working directory is the Django project, but that's unlikely to be the case unless you specifically changed it in the wsgi file. However, you should not be logging to a separate file. The default logging setup will log either to Apache's own log in /var/log or in a site-specific one in a subdirectory of that. Remove your extra configuration and let
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more tomcat error logging about Stack Overflow the company Business Learn more about hiring developers or posting django print to console from view ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack
Django Log To Console Runserver
Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How do you log server errors on django sites up vote http://stackoverflow.com/questions/22470877/how-to-debug-django-with-logging-on-apache 139 down vote favorite 76 So, when playing with the development I can just set settings.DEBUG to True and if an error occures I can see it nicely formatted, with good stack trace and request information. But on kind of production site I'd rather use DEBUG=False and show visitors some standard error 500 page with information that I'm working on fixing this bug at this moment ;) At the http://stackoverflow.com/questions/238081/how-do-you-log-server-errors-on-django-sites same time I'd like to have some way of logging all those information (stack trace and request info) to a file on my server - so I can just output it to my console and watch errors scroll, email the log to me every hour or something like this. What logging solutions would you recomend for a django-site, that would meet those simple requirements? I have the application running as fcgi server and I'm using apache web server as frontend (although thinking of going to lighttpd). python django error-logging share|improve this question asked Oct 26 '08 at 14:37 kender 34.9k2083126 something from battle ground: dlo.me/what-to-do-when-your-site-goes-viral –Cherian May 9 '11 at 3:31 1 Sentry to view logs:readthedocs.org/docs/sentry/en/latest/index.html –Cherian May 9 '11 at 3:31 add a comment| 6 Answers 6 active oldest votes up vote 74 down vote accepted Well, when DEBUG = False, Django will automatically mail a full traceback of any error to each person listed in the ADMINS setting, which gets you notifications pretty much for free. If you'd like more fine-grained control, you can write and add to your settings a middleware class which defines a method named process_exception(), which will have access to the exception that was raised: http://docs.djangoproject.com/en/dev/topics/http/middleware/#
middleware apache https://djangosnippets.org/snippets/1731/ errors modwsgi exceptions Score: 3 (after 4 ratings) Download Raw Add this to your middleware to log errors to the Apache error log when running under mod_wsgi. 1 2 3 4 5 6 7import traceback class WsgiLogErrors(object): def error log process_exception(self, request, exception): tb_text = traceback.format_exc() url = request.build_absolute_uri() request.META['wsgi.errors'].write(url + '\n' + str(tb_text) + '\n') More like this Comments adroffner (on October 2, 2009):
This WSGI middleware is not necessary to get mod_wsgi to use the Python logging apache error log module.
mod_wsgi (version 2.5) sends sys.stderr to the Apache2 virtual host's error_log. Therefore, one only needs to create a logging.StreamHandler() on the sys.stderr stream (the default).
Create a site_logging.py module to do this (see below). Then, just import site_logging into the settings.py on start-up.
After that, write logging statements in any module.
import logging
logging.warn('WSGI sends to the Apache2 error_log.')
MOD_WSGI site_logging.py
import logging
import sys
logger = logging.getLogger('')
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stderr)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(levelname)-8s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
# Please login first before commenting. Written by various people. Hosted by Heroku, powered by Django About | FAQ | Terms of service | Legal notices Flag: --------- Spam Inappropriate Flag this snippet