On this page
article
Logging Decorator
Log function entry and exit.
Category: decorators
Problem
Log function entry and exit.
Solution
def logged(fn):
@wraps(fn)
def wrapper(*a, **k):
logger.info('call %s', fn.__name__)
return fn(*a, **k)
return wrapper
Notes
- Adapt variable names and paths to your project
- Add error handling for production use
- See related chapters in the Learning Path