python - Error Logging in Django and Gunicorn -
i want logging in django , gunicorn, when error. study tdd python, http://chimera.labs.oreilly.com/books/1234000000754/ch17.html#_setting_up_logging
this code. /etc/init/gunicorn-superlists-staging.mysite.com.conf
description "gunicorn server superlists-staging.mysite.com" start on net-device-up stop on shutdown respawn setuid junsu chdir /home/junsu/sites/superlists-staging.mysite.com/source exec ../virtualenv/bin/gunicorn \ --bind unix:/tmp/superlists-staging.mysite.com.socket \ --access-logfile ../access.log \ --error-logfile ../error.log \ superlists.wsgi:application
accounts/authentication.py
import requests import logging django.contrib.auth import get_user_model user = get_user_model() persona_verify_url = 'https://verifier.login.persona.org/verify' domain = 'localhost' class personaauthenticationbackend(object): def authenticate(self, assertion): logging.warning('authenticate function') response = requests.post( persona_verify_url, data={'assertion': assertion, 'audience': settings.domain} ) logging.warning('got response form persona') logging.warning(response.content.decode()) if response.ok , response.json()['status'] == 'okay': email = response.json()['email'] try: return user.objects.get(email=email) except user.doesnotexist: return user.objects.create(email=email) def get_user(self, email): try: return user.objects.get(email=email) except user.doesnotexist: return none
superlists/settings.py
[....] logging = { 'version': 1, 'disable_existing_logger': false, 'handlers': { 'console': { 'level': 'debug', 'class': 'logging.streamhandler', }, }, 'loggers': { 'django': { 'handlers': ['console'], }, }, 'root': {'level': 'info'}, }
my "error.log" log this.
[2016-02-08 14:42:56 +0900] [3355] [info] listening at: unix:/tmp/superlists-staging.mysite.com.socket (3355) [2016-02-08 14:42:56 +0900] [3355] [info] using worker: sync [2016-02-08 14:42:56 +0900] [3359] [info] booting worker pid: 3359 [2016-02-08 14:58:22 +0900] [3355] [info] handling signal: term [2016-02-08 14:58:22 +0900] [3355] [info] shutting down: master [2016-02-08 14:58:22 +0900] [3470] [info] starting gunicorn 19.4.3 [2016-02-08 14:58:22 +0900] [3470] [info] listening at: unix:/tmp/superlists-staging.mysite.com.socket (3470) [2016-02-08 14:58:22 +0900] [3470] [info] using worker: sync [2016-02-08 14:58:22 +0900] [3474] [info] booting worker pid: 3474
i want see error loging, can do?
tl;dr there's nothing wrong code
it seems you've followed linked tutorial correctly, , find log files in /home/junsu/sites/superlists-staging.mysite.com/
dir.
regardless, there few points address in question, i'll try that.
loggers , handlers
the settings module reference above sets single logging handler console
(streamhandler), , single django
logger can use handler.
the root
logger not define handlers, , "django" log stderr
, , level info , above. ran quick test, , root
logger has streamhandler
defined default.
your authentication.py
module calls logging.warning
logs root
logger (i.e logger = logging.getlogger(); logger.warning('stuff')
). however, may want define more specific handler easier locate log of module. explained in section of referenced tutorial.
gunicorn redirects stderr default
it seems by default set capture stderr
stream, redirect log file. however, suggestion use daemonizing app (seems you're using upstart
) log stderr/out.
upstart logging
as explained in gunicorn docs, configuring upstart
pretty simple.
if remove --error-logfile
option in /etc/init/gunicorn-superlists-staging.mysite.com.conf
config, gunicorn default logging it's output stderr
can captured upstart in whatever manner prefer.
if using upstart 1.7 or greater, stdout/err capturing should enabled default. if, however, use earlier version of upstart, suggestion add a console log
option in config , output (stdout/stderr) logged (i assume) /var/log/upstart/gunicorn-superlists-staging.mysite.com.log
Comments
Post a Comment