Java / Java 17 Garbage Collection Interview Questions
How do you enable GC logging in Java 17?
Java 17 uses the unified JVM logging framework (introduced in JDK 9) via the -Xlog flag, which replaced the older per-collector flags like -XX:+PrintGCDetails.
A typical production-ready configuration looks like:
-Xlog:gc*:file=gc.log:time,uptime,level,tags:filecount=5,filesize=20M
Here, gc* selects all GC-related log tags, the file= section directs output to a rotating log file, the decorators (time,uptime,level,tags) control what metadata prefixes each line, and filecount/filesize enable log rotation so files don't grow unbounded.
You can also narrow the scope, for example -Xlog:gc+heap=debug to focus on heap-region-level detail when diagnosing a specific issue.
More Related questions...