How to clear server.log in JBoss?

IAdapter picture IAdapter · Jan 5, 2011 · Viewed 13k times · Source

How do I clear JBoss' server.log file when JBoss is running? When I try to do

echo 1 > server.log

I get error msg that the file is being used by another program (JBoss). Is it possible to use a command-line tool (windows or linux(I do have CygWin)) or an application that I can write myself to clear that file?

P.S. I don't need that file to have 0kb, but I want it to have less than 100MB.

Answer

Péter Török picture Péter Török · Jan 5, 2011

By default JBoss keeps the file locked, since it is writing log messages into it. It is locked as long as JBoss is running and I don't know of other way to release it than stopping JBoss itself.

To keep its size under control, you can modify your log configuration, which is by default in <server>/conf˛jboss-log4j.xml. You can specify the maximum size of a log file, and define what to do when that size is reached: roll over to a new file, truncate the existing one and start writing over it again, etc.

A basic example (not tested, so no guarantee that it works straight as it is):

    <appender name="ROLL" class="org.apache.log4j.rolling.RollingFileAppender">
            ...
            <param name="maxFileSize" value="100MB" />
            ...
    </appender>

Moreover, with the maxBackupIndex parameter you may define the number of backup files (default is 1).