Skip to content

Instantly share code, notes, and snippets.

@aoshiman
Created May 10, 2016 03:40
Show Gist options
  • Save aoshiman/1d044a882417e082a89135e83e49b37a to your computer and use it in GitHub Desktop.
Save aoshiman/1d044a882417e082a89135e83e49b37a to your computer and use it in GitHub Desktop.
dacorator
# -*- 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