Skip to content

Instantly share code, notes, and snippets.

@pferreir
Created July 24, 2014 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pferreir/0be3ddfe69011c2d0114 to your computer and use it in GitHub Desktop.
Save pferreir/0be3ddfe69011c2d0114 to your computer and use it in GitHub Desktop.
diff --git a/indico/core/logger.py b/indico/core/logger.py
index 982c976..c290c28 100644
--- a/indico/core/logger.py
+++ b/indico/core/logger.py
@@ -61,15 +61,20 @@ class IndicoMailFormatter(logging.Formatter):
try:
info.append('Request: %s' % request.id)
info.append('URL: %s' % request.url)
- info.append('Endpoint: %s' % request.url_rule.endpoint)
+
+ if request.url_rule:
+ info.append('Endpoint: {0}'.format(request.url_rule.endpoint))
+
info.append('Method: %s' % request.method)
if rh:
info.append('Params: %s' % rh._getTruncatedParams())
- try:
- info.append('User: %r' % session.user)
- except POSError:
- # If the DB connection is closed getting the avatar may fail
- info.append('User id: %s' % session.get('_avatarId'))
+
+ if session:
+ try:
+ info.append('User: {0}'.format(session.user))
+ except POSError:
+ # If the DB connection is closed getting the avatar may fail
+ info.append('User id: {0}'.format(session.get('_avatarId')))
info.append('IP: %s' % request.remote_addr)
info.append('User Agent: %s' % request.user_agent)
info.append('Referer: %s' % (request.referrer or 'n/a'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment