How to clear server.log in JBoss?

13,551

Solution 1

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).

Solution 2

JBoss locks the file as long as the logging process is running.

If you enabled the JMX console you can stop the logging, delete / modify the log, and start the logging service again.

The url should look something like this (for log4j):

http://jboss.example.com:8080/jmx-console/HtmlAdaptor?action=inspectMBean&name=jboss.system%3Atype%3DLog4jService%2Cservice%3DLogging

I tested this with JBoss 5.

This solution should be scriptable as well.

Regarding your log file size problem: You should use a configuration approach instead of editing the log file manually.

Share:
13,551
IAdapter
Author by

IAdapter

Updated on June 14, 2022

Comments

  • IAdapter
    IAdapter almost 2 years

    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.