How to handle error by myself while using Loguru

556 Views Asked by At

I have some sentence with custom encoded characters. when using Loguru, it raises UnicodeEncodeError because it can't encode my sentence due to those custom characters, so I hope I can handle error by myself, what should I do?

1

There are 1 best solutions below

0
typing.cat13 On

you can wrap logger with try-except:

def log(message):
    try:
        loguru.logger.info(message)
    except UnicodeEncodeError:
        print('...')