xxxxxxxxxx
from functools import wraps
def logit(func):
@wraps(func)
def with_logging(*args, **kwargs):
print(func.__name__ + " was called")
return func(*args, **kwargs)
return with_logging
@logit
def addition_func(x):
"""Do some math."""
return x + x
result = addition_func(4)
# Output: addition_func was called
xxxxxxxxxx
import logging
try:
# Code that might raise an exception
pass
except Exception as e:
logging.error("An exception occurred: %s", str(e))