Created
June 9, 2015 13:17
-
-
Save radoslawroszkowiak/8d85d0a73e6511f5dce8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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