Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Logging with local variables and fix for missing logos.

  • Loading branch information...
commit 2a4a1efd0d4470a7b662c16bfff89733af19f073 1 parent e788d33
@jace jace authored
Showing with 46 additions and 0 deletions.
  1. +40 −0 loghandler.py
  2. +3 −0  views.py
  3. +3 −0  website.py
View
40 loghandler.py
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+
+import logging
+import cStringIO
+import traceback
+
+class LocalVarFormatter(logging.Formatter):
+ def formatException(self, ei):
+ tb = ei[2]
+ while 1:
+ if not tb.tb_next:
+ break
+ tb = tb.tb_next
+ stack = []
+ f = tb.tb_frame
+ while f:
+ stack.append(f)
+ f = f.f_back
+ stack.reverse()
+
+ sio = cStringIO.StringIO()
+ traceback.print_exception(ei[0], ei[1], ei[2], None, sio)
+
+ for frame in stack:
+ print >> sio
+ print >> sio, "Frame %s in %s at line %s" % (frame.f_code.co_name,
+ frame.f_code.co_filename,
+ frame.f_lineno)
+ for key, value in frame.f_locals.items():
+ print >> sio, "\t%20s = " % key,
+ try:
+ print >> sio, repr(value)
+ except:
+ print >> sio, "<ERROR WHILE PRINTING VALUE>"
+
+ s = sio.getvalue()
+ sio.close()
+ if s[-1:] == "\n":
+ s = s[:-1]
+ return s
View
3  views.py
@@ -249,6 +249,9 @@ def logoimage(hashid):
post = JobPost.query.filter_by(hashid=hashid).first()
if post is None:
abort(404)
+ if not post.company_logo:
+ # If there's no logo (perhaps it was deleted), don't try to show one
+ abort(404)
if post.status == POSTSTATUS.REJECTED:
# Don't show logo if post has been rejected. Could be spam
abort(410)
View
3  website.py 100644 → 100755
@@ -6,6 +6,7 @@
from app import app
import models, forms, views, admin, assets, uploads, search
from models import db
+import loghandler
app.config.from_object(__name__)
try:
@@ -19,7 +20,9 @@
search.configure()
views.mail.init_app(app)
+log_formatter = loghandler.LocalVarFormatter()
file_handler = logging.FileHandler(app.config['LOGFILE'])
+file_handler.setFormatter(log_formatter)
file_handler.setLevel(logging.WARNING)
app.logger.addHandler(file_handler)
if app.config['ADMINS']:
Please sign in to comment.
Something went wrong with that request. Please try again.