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


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) 级别:我们在不同的级别执行日志记录,可用的级别为 error、warning、info、debug、trace 和 develop。要禁用日志记录,然后使用替代选项 off。

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

更新于: 2020-03-12

443 次查看

开启你的职业生涯

通过完成课程获得认证

开始
广告