back to all blogsSee all blog posts

Time-based log rollover and enhancements to LogRecordContext extension in Open Liberty

image of author
Ryan Storey on Jun 9, 2022
Post available in languages:

Open Liberty offers time-based log rollover, which enables you to specify a time of day for log files to roll over. This release also includes the addition of the application name to the LogRecordContext Extension and a corresponding JSON logging field.

The Open Liberty includes the following beta features (along with all GA features):

Time-based log rollover for Liberty

Liberty provides a few different log files; a message.log is created by default, and a trace.log and http_access.log can be enabled for tracing and NCSA access logs respectively. Previously, these log files could be rolled over only by either server restart or by limiting the maximum log file size with the maxFileSize logging attribute. Instead of file size-based log rollover, users may want to roll over their files at periodic times to facilitate their existing log cleaning or archival processes.

Now, you can enable time-based periodic rollover of those log files at their own specified time of day by using two new optional logging configuration attributes: rolloverInterval and rolloverStartTime. Upon roll over, the file names are appended with a timestamp that corresponds to the time that the log was rolled over.

  • rolloverInterval is the desired time interval between log rollovers. Set the attribute with a positive integer followed by a unit of time, which can be days (d), hours (h), or minutes (m). For example, specify 5 hours as `5h. You can include multiple values in a single entry. For example, `1d5h is equivalent to 1 day and 5 hours.

  • rolloverStartTime is the time of day when logs first roll over and the first rollover interval duration begins. Valid values for this attribute follow a 24-hour ISO-8601 time format of HH:MM, where 00:00 represents midnight.

The two configuration attributes are optional. If neither of the attributes are set, then time-based log rollover is not enabled. If only one of the two attributes is set, then time-based log rollover is enabled, and the other attribute is set to its default. The default value for rolloverInterval is 1d, and the default value for rolloverStartTime is 00:00.

Example server.xml file configuration for log rollover in the messages.log and trace.log files by specifying the new attributes in the logging element:

    <logging rolloverStartTime="00:00" rolloverInterval="1d"/>

Example server.xml file configuration for log rollover in the http_access.log file by specifying the new attributes in the httpAccessLogging element:

    <httpAccessLogging rolloverStartTime="00:00" rolloverInterval="1d" logFormat='%h %u %{t}W "%r" %s %b' />

Example server.xml configuration for access logging, using <accessLogging/> under <httpEndpoint/>, which handles http_access.log rollover:

   <httpEndpoint id="defaultHttpEndpoint">
      <accessLogging rolloverStartTime="00:00" rolloverInterval="1d" logFormat='%h %i %u %t "%r" %s %b' />

Example result of logs, rolled over every minute, with a configuration of rolloverInterval="1m" and rolloverStartTime="00:00":

Example logs

For more information about this feature, refer to the HTTP Access Logging, Liberty Logging, and Liberty Access Logging documentation.

Add application name to LogRecordContext Extension and as JSON logging field

Previously, Liberty logs did not contain the application name in the LogRecordContext extension. If you were using a log analysis tool, such as the ELK stack, you couldn’t filter out application logs, since the JSON fields did not have a field for the application name.

In Open Liberty, when application log messages are logged and the application name is known, the application name is added to the LogRecordContext, with the key appName and the value being the application name that the message was logged from. When JSON logging is enabled, a new default JSON field (ext_appName) is added to the JSON application logs, which contains the application name that the log message was logged from.

You can use this function by enabling JSON logging support for your Liberty logs.

Example JSON logging snippet:

  "message":"TESTAP0001W: Test Message.",
  "ext_thread":"Default Executor-thread-31"

For more information, check out the JSON Logging and JSON Log Events list documentation.

Try it now

To try out these features, just update your build tools to pull the Open Liberty All Beta Features package instead of the main release. The beta works with Java SE 18, Java SE 17, Java SE 11, and Java SE 8.

If you’re using Maven, here are the coordinates:


Or for Gradle:

dependencies {
    libertyRuntime group: 'io.openliberty.beta', name: 'openliberty-runtime', version: '[,)'

Or take a look at our Downloads page.

Your feedback is welcomed

Let us know what you think on our mailing list. If you hit a problem, post a question on StackOverflow. If you hit a bug, please raise an issue.