There are several logging.warn('....') calls in the legacy code base I am working on today.
I want to understand the log output better. Up to now logging.warn() does emit one line. But this single line is not enough to understand the context.
I would like to see the stacktrace of the interpreter.
Since there are a lot of logging.warn('....') lines in my code, I would like to leave them like they are and only modify the configuration of the logging.
How can I add the interpreter stacktrace to every warn() or error() call automatically?
I know that logging.exception("message") shows the stacktrace, but I would like to leave the logging.warn() lines untouched.
The answer I was looking for was given by @Martijn Pieters♦ in the comments
In python 3.x
logger.warning(f'{error_message}', stack_info=True)
does exactly what you need.
Thanks @Martijn Pieters♦
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With