Skip to content
Browse files

improved logging

git-svn-id: https://svn.bluedynamics.eu/svn/module/bda.bfg.tile/trunk@343 f119a143-da5b-4457-81e3-bee00661a780
  • Loading branch information...
1 parent 5ffb47f commit 65e18bc69a16390c9e66e0c5f0c268eda0972909 jensens committed Dec 31, 2009
Showing with 15 additions and 7 deletions.
  1. +15 −7 src/bda/bfg/tile/_api.py
View
22 src/bda/bfg/tile/_api.py
@@ -10,14 +10,15 @@
queryUtility,
getMultiAdapter,
ComponentLookupError,
- getSiteManager,
)
from repoze.bfg.interfaces import (
IRequest,
IResponseFactory,
IAuthenticationPolicy,
- IAuthorizationPolicy,
+ IAuthorizationPolicy,
+ IDebugLogger,
)
+from repoze.bfg.settings import get_settings
from repoze.bfg.configuration import _secure_view
from repoze.bfg.threadlocal import get_current_registry
from repoze.bfg.path import caller_package
@@ -81,17 +82,19 @@ def __init__(self, path, attribute):
def __call__(self, model, request):
self.model = model
self.request = request
- self.prepare() # XXX maybe remove.
+ self.prepare() # TODO: discuss if needed. i think yes (jens)
if not self.show:
return u''
if self.path:
try:
return render_template(self.path, request=request,
model=model, context=self)
except Exception, e:
- # XXX: do not catch exception if in debug mode.
- # todo: check if debug mode and raise, else return as following
- return u"Error:<br /><pre>%s</pre>" % e
+ settings = get_settings()
+ if settings['debug']:
+ logger = IDebugLogger()
+ logger.debug(u'Exception in %s:\n%s' % (repr(tile), e))
+ return u"Error while rendering tile %e." % repr(tile)
renderer = getattr(self, self.attribute)
result = renderer()
return result
@@ -107,6 +110,7 @@ def render(self):
return u''
def redirect(self, url):
+ # why do we need a redirect in a tile!?
self.request.environ['redirect'] = url
@property
@@ -134,7 +138,11 @@ def consumer(context, request):
try:
tile(context, request)
except Unauthorized, e:
- # TODO: Log in debug mode
+ settings = get_settings()
+ if settings['debug_authorization']:
+ logger = IDebugLogger()
+ logger.debug(u'Unauthorized tile %s called, ' % repr(tile) +
+ u'returns empty string. Full exception:\n %s' % e)
return u''
return consumer

0 comments on commit 65e18bc

Please sign in to comment.
Something went wrong with that request. Please try again.