Tomcat not logging until file is "touched"

837 views Asked by At

Really weird situation here: our tomcat access logfile is showing 0 bytes and an out-of-date modified date in Windows (Server 2012) Explorer. It's apparently empty and WinScp agrees and is not copying it - presumably because it apparently has not changed or is apparently empty. We kinda "know" that the file is being modified though.

However, as soon as we open the logfile in Notepad++ it "updates" and we see 731KB and data in the file though the timestamp remains old. Even if we just TYPE (i.e. cat) the file we update the size. What on earth could be the cause? Is it just an explorer issue?

enter image description here

1

There are 1 answers

5
Jerry Chin On

buffered
Flag to determine if logging will be buffered. If set to false, then access logging will be written after each request. Default value: true

So if you want to see immediate changes to that file, add buffered = "false" to the attributes of your access log valve.

When buffered is set to true(default value), the JVM will start to flush the content ONLY IF the buffer has reached its specified capacity, note that flushing doesn't guarantee that the system will subsequently write the data to physical device immediately, though it's often the case; In addition, the log file practically is never closed, the valve just keeps flushing new content to it.

That probably explains why the modified date is intact.

Reference: http://tomcat.apache.org/tomcat-6.0-doc/config/valve.html#Access_Log_Valve