Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making .log files persistent

I have a software which generates .log files, and the problem is that they are not persistent (each time the programs try to write an event it might rewrite over an past event which is not desirable)

Do you know a way in which I can write a python script for detecting when the program is opening a .log file in order to write something and make sure that he is not overwriting?

Thanks!

like image 605
D D Avatar asked Jun 28 '26 00:06

D D


1 Answers

In Python, the logging package defaults to append

import logging

logging.basicConfig(
            filename=<out-path>, # to print stdout to file
            format=line_format,
            level=logging.DEBUG)

Then, you can write to the logfile by

logging.info(.)

or another one of logging's levels.

like image 92
en casa Avatar answered Jun 30 '26 02:06

en casa



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!