Java 9 Unified JVM Logging


Java 9 provides a common logging system for JVM components with extremely detailed level, an infrastructure to do the logging. With new command-line option -Xlog for all logging followed settings, Unified JVM Logging gives us a precise, easy-to-configure tool to do a root cause analysis of complex system-level JVM components.

I. Available Settings

The command line -Xlog is used for controlling all logging JVM components. Its arguments follow the rules:
– Multiple arguments will be applied in the order they appear on command line.
– Last configuration rules: for the same output, multiple arguments will override each other in the given order.

-Xlog:disable turns off all logging and clears all configuration of the logging framework (including warnings and errors).

The syntax for configuring the logging:

-Xlog:help prints -Xlog usage syntax and available tags, levels, decorators along with some example command lines:

1. Tags

When a log message is shown, it should be associated with a set of tags in the JVM which identify by names: os, gc, modules

– We can apply different settings for individual tags.
– ‘*’ denotes ‘wildcard’ tag match. Not using ‘*’ means all messages matching exactly the specified tags.

2. Levels

We can perform logging at different levels. The available levels are error, warning, info, debug, trace and develop.

To disable logging, use the alternative off.

3. Outputs

The output currently supports 3 types: stdout, stderr, or a text file, which can be set up for log file rotation based on written size and a number of files to rotate (for example: each 10MB, keep 5 files in rotation)

4. 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

Default settings

. tag-set: all.
. level: info
. output: stdout
. decorators: uptime, level, tags

II. Example

-Xlog:gc* com.javasampleapproach.java9.Java9Starter

-Xlog:gc*,os com.javasampleapproach.java9.Java9Starter

-Xlog:os=debug,gc*=debug:stdout:pid,level,tags com.javasampleapproach.java9.Java9Starter

By grokonez | April 7, 2017.

Last updated on September 11, 2018.

Related Posts

Got Something To Say:

Your email address will not be published. Required fields are marked *