How to set the Max Log size in WildFly

This article will teach you which are the strategies to configure a maximum size of your logs in WildFly by using some of the available Log handlers. We will learn how to define the maximum log size both with the Command Line and the XML configuration.

WildFly out of the box provides several built-in Log Handlers.:

  1. ConsoleHandler: This handler sends log messages to the console (stdout or stderr).
  2. FileHandler: Writes log messages to a specified file.
  3. PeriodicRotatingFileHandler: Rotates log files based on a specified time interval.
  4. SizeRotatingFileHandler: Rotates log files based on a specified file size.
  5. PeriodicSizeRotatingFileHandler: Combination of PeriodicRotatingFileHandler and SizeRotatingFileHandler, rotating logs based on both time and file size.
  6. AsyncHandler: Sends log messages asynchronously to another handler.
  7. CustomHandler: Allows you to define a custom logging handler by implementing the appropriate interface.

In order to limit the size of the log file you can either use the SizeRotatingFileHandler or the PeriodicSizeRotatingFileHandler. Let’s see them in detail.

Configuring the SizeRotatingFileHandler

This Logging Handler is the simplest choice if you want to define a maximum size for your logs. The key settings that you can apply are the following ones:

  • rotate-size: The size at which to rotate the log file. (KB)
  • max-backup-index: The maximum number of backups to keep.

The following is a sample XML configuration for a size-rotating-file-handler:

<size-rotating-file-handler name="SizeHandler" autoflush="true">
        <file relative-to="jboss.server.log.dir" path="server.log"/>
        <rotate-size value="30000"/>
        <max-backup-index value="3"/>
        <append value="true"/>

Once your logs reaches the rotate-size, you will see that the logs will start to rotate in your log folder:

jboss max size for logs

it is recommended that you apply configuration changes with the CLI. The following command will create the above Size Rotating Handler definition:

/subsystem=logging/size-rotating-file-handler=SizeHandler:add(append=true,file={relative-to="jboss.server.log.dir",path="server.log"},rotate-size=30000 , autoflush=true,max-backup-index=3)

Then, you can either bind the Handler with a Logger for a specific package or bind it with the Root Logger:


Configuring the PeriodicSizeRotatingFileHandler

This handler combines features from both the size-rotating-file-handler and periodic-rotating-file-handler.

The Periodic Size Rotating File Handler triggers rotation when you either reach the maximum log file size or when a designated time interval elapses. The time interval is determined by the suffix appended to the log file name. For instance, using “.yyyy-MM-dd” would trigger rotation daily, while “.yyyy-MM-dd_HH:mm” would cause rotation every minute.

Here is an example configuration for a PeriodicSizeRotatingFileHandler:

<periodic-size-rotating-file-handler name="PeriodicSizeHandler" autoflush="true">
	<file relative-to="jboss.server.log.dir" path="server.log"/>
	<rotate-size value="30000"/>
	<max-backup-index value="3"/>
	<suffix value=".yyyy-MM-dd"/>
	<append value="true"/>

You can create the above configuration with the following CLI command:

/subsystem=logging/periodic-size-rotating-file-handler=PeriodicSizeHandler:add(append=true,file={relative-to="jboss.server.log.dir",path="server.log"},rotate-size=30000 ,suffix=".yyyy-MM-dd", autoflush=true,max-backup-index=3)

Then, in order to bind it with the Root Logger:



This article was a walk through some of the options available in WildFly to define the maximum size for your server logs.