Skip to content

Instantly share code, notes, and snippets.

@radoslawroszkowiak
Created June 9, 2015 13:17
Show Gist options
  • Save radoslawroszkowiak/8d85d0a73e6511f5dce8 to your computer and use it in GitHub Desktop.
Save radoslawroszkowiak/8d85d0a73e6511f5dce8 to your computer and use it in GitHub Desktop.
def log_execution(func):
"""
The time measuring and logging decorator.
"""
@functools.wraps(func)
def _inner(self, *args, **kwargs):
"""
Proxy, inner function of the log_execution decorator.
"""
try:
start = timeit.default_timer()
result = func(self, *args, **kwargs)
elapsed_time = timeit.default_timer() - start
logger.info(
'%s - executed for Plone Site: "%s" in %s seconds.' % (
func.__name__, self.site.id, str(round(elapsed_time, 3)))
)
return result
except Exception as exc:
self.errors = True
logger.error(
'An error occurred while executing "%s" on '
'a "%s" Plone Site: "%s"' % (
func.__name__, self.site.id, exc.message
))
raise exc
return _inner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment