Configuring size-rotating-file-handler in JBoss EAP 6/7

Solution Verified - Updated

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.x
    • 7.x

Issue

  • How to use SizeRotating file handler in the domain mode of JBoss EAP 6?
  • Provide an example of rotating log appender
  • How is the size-rotating-file-handler configured?
  • We are using Jboss-eap-6.1.1 and trying to rotate logs by size and want to back up max 5 files. Following are the changes we have made to standalone-full.xml file.
  • Need to rotate my JBoss log with size

Resolution

Example definition below where the appender will create a new file once 10 meg size is reached and will retain 100 of the resulting files.

Defining the handler:

<size-rotating-file-handler name="SIZEDFILE">
                <file path="server.log" relative-to="jboss.server.log.dir"/>
                <rotate-size value="10m"/>
                <max-backup-index value="100"/>
</size-rotating-file-handler>

Adding the handler to root-logger

<root-logger>
                <level name="INFO"/>
                <handlers>
                ...
                <handler name="SIZEDFILE"/>
                </handlers>
</root-logger>

The above configuration will be achieved using the following JBoss CLI commands:

/subsystem=logging/size-rotating-file-handler=SIZEDFILE:add(file={path="server.log",relative-to="jboss.server.log.dir"},rotate-size=10m,max-backup-index=100)
/subsystem=logging/root-logger=ROOT:add-handler(name=SIZEDFILE)
/subsystem=logging/root-logger=ROOT:remove-handler(name=FILE)

For JBoss EAP 6.1.1 and earlier, note that switching to the size rotating handler has been known to induce the issue described in Using results in no log messages (JBAS011511) on EAP 6.1.x

See JBoss EAP documentation Configuration Guide about how to configure size log handler.

From JBoss EAP 7.3 onward we can compress the server.log using following cli command by changing the suffix attribute. If the suffix attribute ends with {@code .gz} or {@code .zip} the file will be compressed on rotation.

/subsystem=logging/size-rotating-file-handler=SIZEDFILE:write-attribute(name=suffix,value=".yyyy-MM-dd-HH.zip")

For domain configurations, prefix the above command with a specific profile (e.g. /profile=your_profile).

Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.