liveBook · Manning

Log rotation

As explained in Troubleshooting Java, Second Edition

File rotation is a logging technique that distributes successive log data across bounded files and replaces or archives older files.

Log rotation distributes GC output across bounded files instead of allowing one file to grow indefinitely. It improves transfer, processing, retention, and disk-space management. section 11.3

Configure rotation around two limits:

  • Set filecount to define the maximum number of log files. section 11.3
  • Set filesize to limit each file’s size. section 11.3
  • When the active file reaches its limit, create an indexed file and continue writing there. section 11.3
  • When the file limit is reached, overwrite the oldest file to control total storage. section 11.3

Bound GC logs to five 10 MB files

Run `java -Xlog:gc*:file=logs.txt:time,uptime,level,tags:filecount=5,filesize=10M -jar app.jar`. The JVM starts a new file at 10 MB and overwrites the oldest file after reaching five files. section 11.3

java -Xlog:gc*:file=logs.txt:time,uptime,level,tags:
➥filecount=5,filesize=10M -jar app.jar

Use the complete JVM command as a compact reference for enabling GC logging with rotation. section 11.3

How Troubleshooting Java, Second Edition covers it

How deep it goes
Explains file-count and size limits, rollover behavior, indexed files, and oldest-file replacement without descending into JVM logging internals.
Examples
Uses a Java command configured for five 10 MB files and mentions timestamp-based filtering with find or Get-ChildItem.
What you can do after
Operate/configure JVM GC logging with bounded files and select relevant rotated logs for later analysis.
How it connects
Connects GC logs with log retention, disk usage, selective logging, and troubleshooting.

Also explained in

Compare how 4 books explain log rotation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Troubleshooting Java, Second Edition. The section links point to the parts of the book it draws on.