Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prepend entry to log file

Tags:

python

logging

I'm using the Python logging module. Each time I open the log file I have to scroll all the way down to read the latest entries. Is there a way I can make the logger prepend entries to the beginning of file?

like image 518
siamii Avatar asked Oct 29 '25 16:10

siamii


2 Answers

This is not possible through the logger. If you want this, you'll have to write your own custom logger, read all the entries in the log file, add the new entry to the top, then write the entire log file again.

like image 197
Burhan Khalid Avatar answered Oct 31 '25 05:10

Burhan Khalid


I concur with others: prepending to a file is costly, and making your code more complex than it should be. If you view your log using tools such as more or less, then press the capital G key will bring you all the way to the end.

like image 41
Hai Vu Avatar answered Oct 31 '25 07:10

Hai Vu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!