28 lines
581 B
Python
28 lines
581 B
Python
from functools import wraps
|
|
|
|
|
|
def logformat(message="Calling {name}"):
|
|
def logged(func):
|
|
print(f'Adding logging to {func.__name__}')
|
|
|
|
@wraps(func)
|
|
def wrapper(*args, **kwargs):
|
|
fmtargs=dict(
|
|
name=func.__name__,
|
|
func=func,
|
|
)
|
|
print(message.format(**fmtargs))
|
|
return func(*args, **kwargs)
|
|
return wrapper
|
|
return logged
|
|
|
|
|
|
logged = logformat()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
@logged
|
|
def add(x: int, y: int):
|
|
"""Adds two numbers."""
|
|
return x + y
|