Liberty Log Rotation Configuration Guide | Generated by AI
Here’s the short version, then examples you can paste into server.xml.
How Liberty log rotation works
- What rotates:
messages.logandtrace.log. Rotation can be size-based and/or time-based. (openliberty.io) - What does not rotate:
console.log(it’s just stdout/stderr). You can reduce/disable it instead. (openliberty.io, IBM) - Where to configure: the
<logging …/>element inserver.xml. (You can also set the same values inbootstrap.properties/env vars if you need them to apply beforeserver.xmlloads.) (openliberty.io) - Access logs: the HTTP access log has its own time-based rollover settings under
httpAccessLogging/accessLogging. (openliberty.io) - Both size + time: modern Liberty supports time-based rollover in addition to the classic size-based option, so you can use either or both (except for
console.log). (IBM)
Common server.xml recipes
1) Size-based rotation (classic)
Keeps up to 10 files, each up to 256 MB.
<logging
logDirectory="${server.output.dir}/logs"
maxFileSize="256"
maxFiles="10"/>
Effect: when messages.log or trace.log exceeds 256 MB, Liberty rolls it to a timestamped file and keeps at most 10 such files. (Doesn’t affect console.log.) (openliberty.io)
2) Time-based rotation (e.g., daily at midnight)
<logging
rolloverStartTime="00:00"
rolloverInterval="1d"/>
Effect: messages.log and trace.log roll over every day at 00:00. You can use minutes (m) or hours (h) too, e.g., 30m or 6h. (openliberty.io)
3) Combine size + time (typical production)
<logging
logDirectory="${server.output.dir}/logs"
maxFileSize="256"
maxFiles="14"
rolloverStartTime="00:00"
rolloverInterval="1d"/>
Effect: roll over whichever comes first (size or schedule), and keep a 14-file history. (IBM)
4) Tame or disable console.log growth
console.log can’t rotate; reduce or turn it off and rely on messages.log.
<logging
consoleLogLevel="OFF"
copySystemStreams="false"/>
Notes: turning console off stops Liberty’s own log copy to console.log, but the JVM may still write things like -verbose:gc to stdout/stderr. (openliberty.io)
5) Name/format tweaks (optional)
<logging
messageFileName="messages.log"
traceFileName="trace.log"
messageFormat="JSON"/>
JSON is handy for shipping to a log stack; leave defaults if you don’t need it. (openliberty.io)
HTTP access log (separate from the above)
Enable access logging and roll it daily at midnight:
<httpAccessLogging id="accessLogging"
rolloverStartTime="00:00"
rolloverInterval="1d"/>
<httpEndpoint id="defaultHttpEndpoint"
httpPort="9080" httpsPort="9443"
accessLoggingRef="accessLogging"/>
(Or put rolloverStartTime/rolloverInterval directly on an <accessLogging …/> child of httpEndpoint.) (openliberty.io)
Quick checklist
- Use
maxFileSize+maxFilesfor size-based rollover. (openliberty.io) - Use
rolloverStartTime+rolloverIntervalfor time-based rollover. (openliberty.io) - Don’t expect
console.logto rotate; setconsoleLogLevel="OFF"andcopySystemStreams="false"if you want to avoid large console files. (openliberty.io, IBM)
If you share your current server.xml snippet or your retention goals (e.g., “keep ~7 days” or “cap at 2 GB”), I’ll tailor the exact values.