Logging with the Unified JVM Logger - Java Native OS

Java examples for Native OS:Log

Introduction

Use the unified JVM logger in Java 9.

To initiate the logging, execute the following statement:

java -Xlog:all:file=test.txt:time,level 

The statement will configure the JVM to log all tags to a file named test.txt.

The following command uses 'gc' using 'trace' level to stdout using the 'uptime' decoration.

java -Xlog:gc=trace:uptime 

There are several options available for the -Xlog flag that indicate "what" to log, and "where" to log in the following format:

-Xlog[:option=<what:level>:<output>:<decorators>:<output-options>] 

The following table list Xlog Decorators.

Decorator Description
Time Current time and date (ISO-8601)
UptimeAmount of time surpassed since the start of the JVM (seconds and milliseconds)
TimemillisSystem.currentTimeMillis() output
Uptimemillis Milliseconds surpassed since the start of the JVM
Timenanos System.nanoTime() output
Uptimenanos Nanoseconds surpassed since the start of the JVM
Pid Process identifier
Tid Thread identifier
Level Associated log message level
Tags Associated log message tag

The possible output options include:

filecount=<file count> 
filesize=<file size in kb> 
parameter=value

Related Tutorials