Video in progress
How is unified JVM logging (-Xlog) structured, and what problems besides GC do you use it for?
The -Xlog syntax is tags=level:output:decorators:options. Beyond GC, I use it to see where a class was loaded from (class+load), safepoints, container limits (os+container), and JIT and metaspace problems.
📖 Answer
Since Java 9 all JVM logs are merged into one system. Every entry has one or more tags (gc, class, load, safepoint...), a level (error..trace) and an output destination.
# tag+tag=level : output : decorators : options
java -Xlog:class+load=info:file=/logs/classload.log:uptime,tid:filecount=3,filesize=10m -jar app.jar
To see which tags exist: java -Xlog:help and java -Xlog:all=trace -version (this prints a lot, just out of curiosity).
The ones I actually use:
-Xlog:class+load=infoshows which jar a class was loaded from. The first thing to reach for with aNoSuchMethodErroror a two-versions-of-a-jar problem;-Xlog:class+unloadwhen checking for a classloader leak;-Xlog:safepointfor pauses that have nothing to do with GC;-Xlog:os+container=trace -versionto check whether the JVM reads the container limits correctly;-Xlog:metaspaceand-Xlog:codecachefor metaspace and the code cache, respectively.
The nicest part is that you can turn it on in a running JVM too.
jcmd <pid> VM.log output=/tmp/sp.log what=safepoint=info decorators=uptime
jcmd <pid> VM.log list
jcmd <pid> VM.log disable # turn everything off (the warnings on stdout go too)
Diagnostics without a restart are a big win on prod. Just don't leave the trace level on for long: the disk fills up fast.
Sign up to mark studied questions and save your progress.