5

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.

Mike
  • 47,263
  • 29
  • 113
  • 177
IAdapter
  • 62,595
  • 73
  • 179
  • 242

3 Answers3

3

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

Péter Török
  • 114,404
  • 31
  • 268
  • 329
1

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.

hennr
  • 2,632
  • 2
  • 23
  • 26
0

To clear logs in JBoss, you can follow these steps:

  1. Stop the JBoss Server: Before you clear the logs, it's a good practice to stop the JBoss server to prevent any potential issues while the logs are being cleared.
  2. Navigate to the Log Directory: Locate the directory where JBoss/WildFly stores its log files. This directory is typically named standalone/log or domain/servers/server-name/log within your JBoss/WildFly installation directory.
  3. Clear the log file
  4. Start the JBoss Server: After you've cleared the logs, you can start the JBoss server again.