亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

java9之后的log

標簽:
Java

java9之后log框架改变了。很多gc日志的参数也变了。设置新的参数,往往有点不知所措。
下面就介绍一下新日志的模式。
样例

java -Xlog:gc*=info Main
[0.011s][info][gc,heap] Heap region size: 1M
[0.014s][info][gc     ] Using G1
[0.014s][info][gc,heap,coops] Heap address: 0x0000000700000000, size: 4096 MB, Compressed Oops mode: Zero based, Oop shift amount: 3
[0.188s][info][gc,heap,exit ] Heap
[0.188s][info][gc,heap,exit ]  garbage-first heap   total 262144K, used 2048K [0x0000000700000000, 0x0000000800000000)
[0.188s][info][gc,heap,exit ]   region size 1024K, 3 young (3072K), 0 survivors (0K)
[0.188s][info][gc,heap,exit ]  Metaspace       used 6238K, capacity 6394K, committed 6528K, reserved 1056768K
[0.188s][info][gc,heap,exit ]   class space    used 544K, capacity 574K, committed 640K, reserved 1048576K


大家可以看到这样的日志似乎变化特别大。
下面是设置的规范

-Xlog[:[selections][:[output][:[decorators][:output-options]]]]

其实设置和使用比原来是简单很多了。使用就几个模块,可能比较麻烦的是找出这些模块。我们下面一个一个看模块。

selections

selections主要是两部分组成,tags和levels。
我们案例里设置的

gc*=info

tag就是gc*,level就是info。

level不写默认就是info。他有以下几种选择,分别代表不同程度的日志,

off, trace, debug, info, warning, error

tag的种类比较多

 add, age, alloc, annotation, aot, arguments, attach, barrier, biasedlocking, blocks, bot, breakpoint, bytecode, cds, census, class, classhisto, cleanup, codecache, compaction, compilation, constantpool, constraints, container, coops, cpu, cset, data, datacreation, dcmd, decoder, defaultmethods, director, dump, ergo, event, exceptions, exit, fingerprint, free, freelist, gc, handshake, hashtables, heap, humongous, ihop, iklass, init, inlining, interpreter, itables, jfr, jit, jni, jvmti, liveness, load, loader, logging, malloc, mark, marking, membername, memops, metadata, metaspace, methodcomparator, mirror, mmu, module, monitorinflation, monitormismatch, nestmates, nmethod, normalize, objecttagging, obsolete, oldobject, oom, oopmap, oops, oopstorage, os, pagesize, parser, patch, path, perf, phases, plab, preorder, preview, promotion, protectiondomain, purge, redefine, ref, refine, region, reloc, remset, resolve, safepoint, sampling, scavenge, setting, smr, stackmap, stacktrace, stackwalk, start, startuptime, state, stats, stringdedup, stringtable, subclass, survivor, sweep, system, table, task, thread, time, timer, tlab, tracking, unload, unshareable, update, verification, verify, vmoperation, vmthread, vtables, vtablestubs, workgang

其实平时用不到这么多,想看的时候可以找出想要的配置上就好。
tag的表达

-Xlog:gc

表示只包含gc标签的,例如

[0.014s][info][gc     ] Using G1
-Xlog:gc*

表示至少包含gc的log,例如gc还有gc和heap的组合。

[0.011s][info][gc,heap] Heap region size: 1M
[0.014s][info][gc     ] Using G1

tag也可以组合

-Xlog:gc,os

用逗号表示或,筛选出只包含gc或者只包含os的。

[0.003s][info][os] Use of CLOCK_MONOTONIC is supported
[0.003s][info][os] Use of pthread_condattr_setclock is not supported
[0.003s][info][os] Relative timed-wait using pthread_cond_timedwait is associated with the default clock
[0.003s][info][os] SafePoint Polling address, bad (protected) page:0x000000010e2bd000, good (unprotected) page:0x000000010e2be000
[0.015s][info][gc] Using G1
-Xlog:gc+heap

用加号表示且,包含gc和heap的日志

[0.010s][info][gc,heap] Heap region size: 1M

特殊用法,利用off的level可以筛选

-Xlog:gc*=info,coops*=off

这里至少包含gc,不能包含coops。会在最初的记录里,去掉了含有coops的记录。

output

out有三种选择。

 stdout
 stderr
 file=

不写默认是stdout。

decorators

decorator就是日志前面的时间,标签等的输出

 time (t), utctime (utc), uptime (u), timemillis (tm), uptimemillis (um), timenanos (tn), uptimenanos (un), hostname (hn), pid (p), tid (ti), level (l), tags (tg)

只要编写decorator,就可以修改日志的输出顺序,以及输出的前面的部分。
默认是

uptime,levels,tags

output-options

filesize
filecount

这里就是控制文件大小和个数的。

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
JAVA開發工程師
手記
粉絲
1.6萬
獲贊與收藏
380

關注作者,訂閱最新文章

閱讀免費教程

  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消