JVM logging system in Java 9 - Levels, tags, output, rotation, decoration

Contents of page >

Common logging system will be introduced for all components of the JVM in java 9.
1) But why this JVM logging is required in java 9?
  • JVM is very complex system system
  • Finding root cause of crash and error is >
    • very difficult and
    • time-consuming task.
  • Finding performance issues are difficult.

So, if good amount of logging is enabled it will be easy to find out root cause of crashes and and fix them, performance also could be improved in java 9.

2) Logging features in java 9 >
  1. Logging levels - Logging can be performed at different levels >
    • error,
    • warning,
    • info,
    • debug,
    • Trace and
    • Develop.
Logging can be customized to select what logs have to logged on basis of levels.

  1. Tags - Log messages categorized using following tags >
    • compiler,
    • gc,
    • classload,
    • metaspace,
    • svc,
    • threads
    • Jfr etc.
One message can have multiple tags in java 9.

  1. Logging redirection - Logging can be redirected to >
    • console or
    • file.

  1. Output - currently three types of output are supported >
  • stdout - It outputs to stdout.
  • stderr - It outputs to stderr.
  • text file - It outputs to text file

  1. Log rotation - Log files could be rotated by size and number of files to keep (similar to what is available for GC logs today)

Example - rotate log file each 2 MB, keep 5 files in rotation.
Example file name -  jvm.log.1, jvm.log.2, jvm.log.3, jvm.log.4, jvm.log.5

  1. By default >
warning and error level are output to stderr.

  1. Logging messages are in plain text, they are in human-readable form.

  1. Decoration - Logging  messages can be decorated. There are following decoration options available in java 9 >
    • time - Current date and time (in ISO-8601 format)
    • Uptime - Time since JVM started in seconds and milliseconds.
    • Level - log message level.
    • Tags - log message tags.
    • pid - process identifier
    • tid - thread identifier

  1. Dynamically configuring logging at runtime using >
    • jcmd or
    • MBeans

  1. Implement following >
    • syslog and
    • Windows Event Viewer output in java 9.

3) Command-line options for JVM logging in java 9 >
It will done using by passing command line argument in java 9.

Disable logs in component of JVM (i.e. even warning and errors) >

Logging help in java 9 >

Default configuration >
   - default configuration if nothing is configured on command line
   - 'all' is a special tag name aliasing all existing tags
   - this configuration will log all messages with a level that
   matches ´warning´ or ´error´ regardless of what tags the
   message is associated with

4) Impact of JVM logging in  in java 9 >
  • performance gets impacted by lots of logging, so be cautious while enabling logging  in java 9. Enable logging only if required. Enable based on levels, decorate it if required.
  • Logging not localized/internationalized.

Summary >
In this java tutorial we learned JVM logging system in Java 9. why this JVM logging is required in java 9? Logging features in java 9. Command-line options for JVM logging in java 9. Impact of JVM logging in  in java 9.

Having any doubt? or you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.


varHandle (variable handle) in java 9

Labels: Core Java Java 9
Must read for you :