Files
OSIT-AE-API-FastAPI/app/log.py

27 lines
1.0 KiB
Python

import functools, logging
log = logging.getLogger('root')
log.setLevel(logging.ERROR) # DEBUG > INFO > WARNING > ERROR > CRITICAL
logging.basicConfig(
format='[%(asctime)s] %(levelname)s @ %(module)s.%(funcName)s()#%(lineno)d: %(message)s'
)
# ### BEGIN ### Log ### logger_reset() ###
# https://realpython.com/primer-on-python-decorators/
# Updated 2022-02-15
def logger_reset(func):
# log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
# log.info(locals())
@functools.wraps(func)
def wrapper(*args, **kwargs):
log.info(f'*** Function: "{func.__name__}()"')
log.debug(f'*** Function Positional Args: {args}\nFunction Key Args: {kwargs}')
init_log_level = log.level
returned_result = func(*args, **kwargs)
log.debug(f'*** Function finished: "{func.__name__}()". Resetting logger level to level: {log.level} ***')
log.setLevel(init_log_level)
return returned_result
return wrapper
# ### END ### Log ### logger_reset() ###