diff --git a/src/logger.py b/src/logger.py index 048893b..d8e632b 100644 --- a/src/logger.py +++ b/src/logger.py @@ -1,5 +1,6 @@ import logging import sys +from functools import wraps from logging.handlers import RotatingFileHandler handlers = [RotatingFileHandler(filename="simple_ddnet_mapper.log", @@ -14,12 +15,17 @@ datefmt='%m/%d/%Y%I:%M:%S %p') -def BroadErrorHandler(func): - def innerFunction(*args, **kwargs): - try: - func(*args, **kwargs) - except Exception as e: - logger.error(f"An error occurred at {func.__name__}") - logger.error(str(e)) +def BroadErrorHandler(logger): + def decorator(func): + @wraps(func) + def innerFunction(*args, **kwargs): + try: + result = func(*args, **kwargs) + return result + except Exception as e: + logger.error(f"An error occurred at {func.__name__}") + logger.error(str(e)) + # raise ValueError("Debug") from e - return innerFunction + return innerFunction + return decorator