1
0
Fork 0
mirror of synced 2024-06-25 17:40:17 +12:00

Add filter for stream logger re exceptions

This commit is contained in:
Serene-Arc 2021-04-05 21:34:03 +10:00 committed by Ali Parlakci
parent b255271016
commit 1768096b85

View file

@ -87,10 +87,18 @@ def cli_archive(context: click.Context, **_):
def setup_logging(verbosity: int):
class StreamExceptionFilter(logging.Filter):
def filter(self, record: logging.LogRecord) -> bool:
result = not (record.levelno == logging.ERROR and record.exc_info)
return result
logger.setLevel(1)
stream = logging.StreamHandler(sys.stdout)
stream.addFilter(StreamExceptionFilter())
formatter = logging.Formatter('[%(asctime)s - %(name)s - %(levelname)s] - %(message)s')
stream.setFormatter(formatter)
logger.addHandler(stream)
if verbosity <= 0:
stream.setLevel(logging.INFO)