Java 9 中的统一 JVM 日志记录是什么?

javaobject oriented programmingprogramming

Java 9 可以为 JVM 组件提供具有详细级别的通用日志记录系统。通过使用新的命令行选项: -Xlog 用于所有日志记录设置 统一 JVM 日志记录为我们提供了一个易于配置的工具来对复杂的系统级 JVM 组件进行根本原因分析 (RCA)

命令行 -Xlog可用于控制所有日志记录 JVM 组件。 -Xlog  的参数遵循以下规则:

  • 多个参数按它们在命令行中出现的顺序应用。
  • 最后的配置规则:对于相同的输出,多个参数可以按给定的顺序相互覆盖。

Xlog: disable 关闭所有日志记录并清除日志记录框架的所有配置(包括 警告错误)。

语法

-Xlog:tag[*][=level][:output:decoration:output-option],tag...

-Xlog: help 打印 -Xlog  使用语法和可用标签、级别、装饰器以及一些示例命令行。

1) 标签:显示日志消息时,它与 JVM 中的一组标签相关联,这些标签通过名称进行标识:os、gc、modules。我们对各个标签应用不同的设置,‘*’ 表示‘通配符’ 标签匹配。

2) 级别:我们在不同的级别执行日志记录,可用的级别包括错误、警告、信息、调试、跟踪和开发。要禁用日志记录,请使用替代关闭。

3) 输出:输出支持三种类型:stdout、stderr 和文本文件,用于根据写入的大小和要轮换的文件数量设置日志文件轮换。

4) 装饰器:有关称为装饰器的消息的更多详细信息。以下是列表:

  • time/timemillis/timenanos:当前时间和日期(ISO-8601格式)
  • uptime/uptimemillis/uptimenanos:自JVM启动以来的时间
  • pid:进程标识符
  • tid:线程标识符
  • level:与日志消息关联的级别
  • tags:与日志消息关联的标签
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, patch, 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.)

相关文章