views:

352

answers:

1

I am using Jboss 4.0.2 in Solaris to run a webapp.

JBoss is configured to use the factory default log4j.xml file, and this has a ConsoleAppender. I am redirecting stdout of jboss java process to a file.

Something interesting happens when I try to cleanup this file - jboss.out.

This is where I start.

$ ls -alhrt jboss.out
-rw-r--r--   1 ipunity  ipunity     458M Jan  8 07:22 jboss.out

Then I clean up this file. Jboss is still running.

$ >jboss.out
$ ls -alhrt jboss.out
-rw-r--r--   1 ipunity  ipunity        0 Jan  8 07:24 jboss.out

Now if go click on a link in my webapp, it starts logging, but the whole file kind of reappears again!

$ ls -alhrt jboss.out
-rw-r--r--   1 ipunity  ipunity     458M Jan  8 07:25 jboss.out

Any ideas on whats going on?

Is ConsoleAppender buffering the data? I dont have enough memory to hold 458MB and my disk swap is almost unused. I dont see any temp file this huge either.

+2  A: 

This is probably a sparse file, created by the OS when JBoss issues a write with the file pointer set to +[whatever the old size of the file was].

Check the disk space actually used by the new file -- on most unices, du -k jboss.out should work. If the file is sparse, you should see something significantly less than the size shown by ls.

Generally, removing log files while they're being written to is tricky. To avoid that issue when capturing stdout, I tend to pipe stdout to a program like cronolog or rotatelogs instead of straight to a file.

pra
It is indeed a sparse file.`$ du -h jboss.out``1.8M jboss.out`Thanks for pointing me to cronolog and rotatelogs. I tried using log4j itself to rotate the log file and its working just fine too.
Vasu