I develop a client-server application and I have log in the server, so I use the logging
module. I would like to create a command in the server to clear the file.
I have test with os.remove()
but after, the log doesn't work.
Do you have an idea?
Thanks.
You'd have to signal to the daemon that the log file's been removed so it can close/reopen the log file handle and start using the new log file. Otherwise it'll just keep writing to the old one, which will still exist somewhere until all filehandles on it are closed. Give mode="w" to logging. FileHandler .
Go to the Admin Logs tab. Click/Tap Clear Log. Note: For hosts/superusers, the selected site's log is cleared. If All is selected, the logs of all sites in the installation are cleared.
StreamHandler. The StreamHandler class, located in the core logging package, sends logging output to streams such as sys. stdout, sys. stderr or any file-like object (or, more precisely, any object which supports write() and flush() methods).
It might be better to truncate the file instead of removing it. The easiest solution is to reopen the file for writing from your clearing function and close it:
with open('yourlog.log', 'w'): pass
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