roshbaik2 / open-zwave

Automatically exported from code.google.com/p/open-zwave
0 stars 0 forks source link

Log File Rotation. #465

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run a program that uses OpenZwave with logging turned on
2. View log file
3. Logrotate the log file with copy truncate
4. Watch log file return to original size
5. View log file and notice null values at the head of the file
6. Log file grows endlessly until it fills up the partition

This issue is explained here:
http://serverfault.com/questions/221337/logrotate-successful-original-file-goes-
back-to-original-size

What is the expected output? What do you see instead?
The log file should start in size at zero and grow from there. Also, there 
should not be null values at the head of the file.

What version of the product are you using? On what operating system?
Domoticz v2.2248 using OpenZwave Version 1.3.1008 on Linux raspberrypi 3.12.36+ 

The fix is to not keep the offset when writing to the log file, but to append 
to the file when writing.

Original issue reported on code.google.com by martywes...@gmail.com on 24 Feb 2015 at 6:28

GoogleCodeExporter commented 9 years ago
I've dug into this a bit more and this issue appears to be caused by holding 
the log file open in the Unix version of LogImpl.cpp. The file is truncated 
underneath the process, but the process still keeps the writing pointer where 
it was so on the next write, it creates a sparse file up to the offset of the 
write.

I have found some information to suggest that calling fflush() will push all 
writes to the files and update the file position pointer, but I have not been 
able to test this myself.

In the meantime, the workaround is to have a post log rotate script that 
restarts the process, which is not ideal.

Original comment by martywes...@gmail.com on 24 Feb 2015 at 8:46

GoogleCodeExporter commented 9 years ago
fflush will not handle a truncated file (which is essentially what happens when 
you remove the file), hence it wont fix the solution. 

There needs to be a way for you to notify OZW to close/open the Log file, but 
its racy. Instead we should implement a function to perform log file rotation 
within OZW. Hence, adding this as a enhancement. 

In the mean time, if your concerned about space, once things are running 
smoothly, turn down the logging. 

Original comment by jus...@dynam.ac on 2 Mar 2015 at 2:37