Can a wrapperdecorator function is Python disable all logging inside the code it wraps

  logging, python, python-decorators

I want to decoratewrap a function and prevent the logging of all logs from within that function’s scope.

def prevent_logs_wrapper(func):
    ...
    ...
    ...

@prevent_logs_wrapper
def some_logs():
    logger.info('Log an info msg')
    logger.warning('Log a warning msg')

and instead of this output

[INFO] Log an info msg
[WARNING] Log an warning msg

we won’t get any logs.

Source: Python Questions

LEAVE A COMMENT