Skip to content
Advertisement

How to get all previous logs written during current run (python logging)

I’m using the python logging module. How can I get all of the previously outputted logs that have been written-out by logger since the application started?

Let’s say I have some large application. When the application first starts, it sets-up logging with something like this

JavaScript

A few hours or days later I want to be able to get the history of all of the log messages ever written by logging and store that to a variable.

How can I get the history of messages written by the python logging module since the application started?

Advertisement

Answer

If you’re writing to a log file, then you can simply get the path to the log file and then read its contents

JavaScript
Advertisement