Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Java

Unified JVM Logging trong Java 9 là gì?

Java 9 cung cấp hệ thống logging thống nhất cho các component JVM với mức độ chi tiết cao. Sử dụng option command-line mới: -Xlog cho tất cả cài đặt logging. Unified JVM Logging cung cấp công cụ dễ cấu hình để phân tích nguyên nhân gốc rễ (RCA) các component JVM phức tạp.

Cú pháp -Xlog

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

Các thành phần

1) Tags

Log message gắn tag xác định component: gc, os, modules, class, jit... Dấu * = wildcard.

2) Levels

off, trace, debug, info, warning, error. off = tắt logging.

3) Outputs

stdout, stderr, file=<filename> (hỗ trợ rotation: size, count).

4) Decorators

DecoratorViết tắtMô tả
time / timemillis / timenanost / tm / tnThời gian hiện tại (ISO-8601)
uptime / uptimemillis / uptimenanosu / um / unThời gian từ khi JVM start
pidpProcess ID
tidtiThread ID
levellMức log
tagstgTag liên quan
hostnamehnTên host

Ví dụ thường dùng

# Log tất cả mức info ra stdout với uptime, level, tags
-Xlog

# Chỉ log GC
-Xlog:gc

# GC + Safepoint
-Xlog:gc,safepoint

# GC level debug ra file, rotate 10MB x 5 files
-Xlog:gc=debug:file=gc.log::filecount=5,filesize=10M

# Tắt toàn bộ logging
-Xlog:disable

# Xem help
-Xlog:help

Output ví dụ java -Xlog:help

-Xlog Usage: -Xlog[:[what][:[output][:[decorators][:output-options]]]]
where 'what' is tag1[+tag2...][*][=level][,...]
Available log levels: off, trace, debug, info, warning, error
Available log decorators: time (t), utctime (utc), uptime (u), timemillis (tm)...
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, init, 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
...

Unified JVM Logging thay thế hàng chục flag -XX:+PrintGC*, -XX:+PrintClassHistogram... cũ – thống nhất, mạnh mẽ, extensible.