Created
May 10, 2016 03:40
-
-
Save aoshiman/1d044a882417e082a89135e83e49b37a to your computer and use it in GitHub Desktop.
dacorator
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
# -*- coding: utf-8 -*- | |
from datetime import datetime | |
from functools import wraps | |
def logging(func): | |
"""A decorator that logs the activity of the script.""" | |
@wraps(func) | |
def wrapper(obj, *args, **kwargs): | |
print("{0:%Y-%m-%d %H:%M:%S} {1} {2} {3} args={4} kwargs={5}"\ | |
.format(datetime.now(), "INFO", func.__qualname__, "START", args, kwargs)) | |
result = func(obj, *args, **kwargs) | |
print("{0:%Y-%m-%d %H:%M:%S} {1} {2} {3} return {4}"\ | |
.format(datetime.now(), "INFO", func.__qualname__, "END", result)) | |
return result | |
return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment