
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Unified JVM Logging in Java 9
In this article, we will learn about the unified JVM logging in Java 9. Logging in the JVM is a great tool for performing root cause analysis, and it is a part of the JDK(Java Development Kit). Starting from JDK 9, the JVM maintainers chose to rebuild the way the JVM logs things.
What is Unified JVM Logging?
Java 9 can provide a common logging system for JVM components with a detailed level. By using a new command-line option: -Xlog for all logging settings, and unified JVM logging, gives us an easy-to-configure tool to do a root cause analysis (RCA) of complex system-level JVM components.
The -Xlog command
The command line -Xlog can be used for controlling all logging JVM components. "-Xlog: disables" command turns off all logging, and clears all configuration of the logging framework (including warnings and errors).
The arguments of -Xlog follow the rules below:
- Multiple arguments have applied in the order they appear in the command line.
- Last configuration rules: for the same output, multiple arguments can override each other in the given order.
Syntax
Below is the syntax of the -Xlog command:
-Xlog:tag[*][=level][:output:decoration:output-option],tag...
-Xlog: help prints -Xlog usage syntax and available tags, levels, and decorators along with some example command lines.
Core Components of Unified JVM Logging
The following are the four main components of Unified JVM Logging:
1. Tags
When a log message is shown, it is associated with a set of tags in the JVM that are identified by names: os, gc, and modules. We apply different settings for individual tags, and ?*' denotes a ?wildcard' tag match.
2. Levels
We perform logging at different levels, and the available levels are error, warning, info, debug, trace, and develop. To disable logging, use the alternative off.
Outputs
The output supports three types:

stdout, stderr, and a text file to set up for log file rotation based on the written size and a number of files to rotate.
Decorators
There are more details about the message called decorators. Here is the list:
- time/timemillis/timenanos: current time and date (ISO-8601 format)
- uptime/uptimemillis/uptimenanos: time since the start of the JVM
- pid: process identifier
- tid: thread identifier
- level: level associated with the log message
- tags: tag associated with the log message
Example
Below is an example to use -Xlog command in Java:
C:\Program Files\Java\jdk-9.0.4\bin>java -Xlog:help -Xlog Usage: -Xlog[:[what][:[output][:[decorators][:output-options]]]] where 'what' is a combination of tags and levels of the form tag1[+tag2...][*][=level][,...] Unless wildcard (*) is specified, only log messages tagged with exactly the tags specified will be matched. Available log levels: off, trace, debug, info, warning, error Available log decorators: time (t), utctime (utc), uptime (u), timemillis (tm), uptimemillis (um), timenanos (tn), uptimenanos (un), hostname(hn), pid (p), tid (ti), level (l), tags (tg) Decorators can also be specified as 'none' for no decoration. Available log tags: add, age, alloc, aot, annotation, arguments, attach, barrier, biasedlocking, blocks, bot, breakpoint, census, class, classhisto, cleanup, compaction, constraints, constantpool, coops, cpu, cset, data, defaultmethods, dump, ergo, exceptions, exit, fingerprint, freelist, gc, hashtables, heap, humongous, ihop, iklass, in it, itables, jni, jvmti,liveness, load, loader, logging, mark, marking, methodcomparator, metadata, metaspace, mmu, module, monitorinflation,monitormismatch, nmethod, normalize, objecttagging, obsolete, oopmap, os, pagesize, , path, phases, plab, promotion,preorder, protectiondomain, ref, redefine, refine, region, remset, purge, resolve, safepoint, scavenge, scrub, stacktrace,stackwalk, start, startuptime, state, stats, stringdedup, stringtable, stackmap, subclass, survivor, sweep, task, thread,tlab, time, timer, update, nload, verification, verify, vmoperation, vtables, workgang, jfr, system, parser, bytecode,setting, event Specifying 'all' instead of a tag combination matches all tag combinations. Described tag combinations: logging: Logging for the log framework itself Available log outputs: stdout, stderr, file= Specifying %p and/or %t in the filename will expand to the JVM's PID and startup timestamp, respectively. Some examples: -Xlog Log all messages using 'info' level to stdout with 'uptime', 'levels' and 'tags' decorations. (Equivalent to -Xlog:all=info:stdout:uptime,levels,tags). -Xlog:gc Log messages tagged with 'gc' tag using 'info' level to stdout, with default decorations. -Xlog:gc,safepoint Log messages tagged either with 'gc' or 'safepoint' tags, both using 'info' level, to stdout, with default decorations. (Messaged tagged with both 'gc' and 'safepoint' will not be logged.)