The problem is most of the time the same !

process 1 writes to a file and 

process 2 intends to look at the files content, asynchronous, at arbitrary 
point in time and space ! 

a viewer (like you) intends to see what he thinks process 1 should have been 
written meanwhile, at arbitrary point in time and space !

 

So - When does process 1 flush it's buffers to disk in a way that process 2 can 
thereafter read the file and find in the file what process 1 has written.

 

The logger as you defined it uses a buffer of size=32767.

 

In short : why should process 1 (the RollingFileAppender) write to disk if it 
has such a large buffer, before this buffer is full?

 

This buffer gets all the data to be written to the file, AND with this large 
buffer you keep IO rate low, AND you risk that you have to wait long for a 
flush to disk to occur, an update toward the disk as you as viewer expect it.

 

Log4j uses either a Writer.class or the BufferedWriter.class from the JDK !!!

 

And you can find in log4j code FileAppender.java the following snippet !

 

    // It does not make sense to have immediate flush and bufferedIO.

    if(bufferedIO) {

      setImmediateFlush(false);

    }

 

 

So your question must be, after how many characters going to your buffer, the 
Writer or BufferedWriter of your JDK must in fact flush it's buffers as output 
to the disk?

 

Be assured, it will flush latest when the buffer capacity is reached!

 

 

 

 

I suggest, take your buffer size down for a test to about 256 bytes and see how 
your IO rate goes up writing short buffers to disk more frequently. If you are 
unhappy with the IO rate then increase it slowly to what you think is a 
reasonable buffer size for you. The default would be 

 

  /**

   * Determines the size of IO buffer be. Default is 8K. 

   */

  protected int bufferSize = 8*1024;

 

 

Hope this helps

 

Josef

 

 

 

-----Ursprüngliche Nachricht-----
Von: Umesh Paliwal [mailto:[email protected]] 
Gesendet: Mittwoch, 14. September 2011 10:51
An: [email protected]
Betreff: log4j logs not getting updated

 

Hi,

 

I have been using log4j 1.2.8 with the following log4j properties :

log4j.rootLogger=WARN, STDOUT

log4j.appender.STDOUT=org.apache.log4j.RollingFileAppender

log4j.appender.STDOUT.MaxBackupIndex=4

log4j.appender.STDOUT.MaxFileSize=10MB

log4j.appender.STDOUT.File=log/Tcp.log

log4j.appender.STDOUT.BufferSize=32768

log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout

 

The logs are not getting updated after a period of time. I need to restart the 
process for the logs to generate again.

 

I have updated the log4j jar to the latest version 1.2.16. But still I have the 
same issue.

 

Please help ...

 

Regards,

Umesh Paliwal

 

 

The information contained in this e-mail is private & confidential and may also 
be legally privileged. If you are not the intended recipient, please notify us, 
preferably by e-mail, and do not read, copy or disclose the contents of this 
message to anyone.

Reply via email to