added logging of all messages to the django.journal.<tag> domain

The text representation of the message is used.

If an exception occurs, we tried to log. It it still does not work,
we give up.
This commit is contained in:
Benjamin Dauvergne 2012-12-11 17:27:53 +01:00
parent 1d897a3dcc
commit deff320526
1 changed files with 10 additions and 0 deletions

View File

@ -1,3 +1,5 @@
import logging
from exceptions import JournalException
from models import (Journal, Tag, Template)
@ -53,6 +55,14 @@ def record(tag, template, using=None, **kwargs):
except (KeyError, IndexError), e:
raise JournalException(
'Missing variable for the template message', template, e)
try:
logger = logging.getLogger('django.journal.%s' % tag)
logger.info(message)
except:
try:
logging.getLogger('django.journal').exception('Unable to log msg')
except:
pass # we tried, really, we tried
journal = Journal.objects.using(using).create(tag=tag, template=template,
message=unicode_truncate(message, 128))
for tag, value in kwargs.iteritems():