Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Java

Unified JVM Logging ใน Java 9 คืออะไร

Java 9 ให้ระบบ logging แบบร่วมมือสำหรับคอมโพเนนต์ JVM ด้วยระดับรายละเอียด ใช้ command-line option ใหม่: -Xlog สำหรับ logging settings ทั้งหมด และ unified JVM logging ให้เครื่องมือง่ายต่อการตั้งค่า เพื่อทำ root cause analysis (RCA) ของคอมโพเนนต์ JVM ระดับระบบที่ซับซ้อน

คำสั่ง -Xlog

ควบคุม logging ของคอมโพเนนต์ JVM ทั้งหมด arguments ของ -Xlog ปฏิบัติตามกติกา:

  • หลาย arguments ใช้ตามลำดับที่ปรากฏใน command-line
  • กติกาการตั้งค่าล่าสุด: สำหรับ output เดียวกัน หลาย arguments สามารถ override กันได้ตามลำดับ

Xlog: disable ปิด logging ทั้งหมด และล้างการตั้งค่าทั้งหมดของ logging framework (รวม warnings และ errors)

ไวยากรณ์

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

-Xlog: help พิมพ์ -Xlog usage syntax และ tags, levels, decorators พร้อมตัวอย่าง command lines

องค์ประกอบหลัก

1) Tags

เมื่อ log message แสดง จะเชื่อมโยงกับชุด tags ใน JVM ที่ระบุชื่อ: os, gc, modules ใช้ settings ต่างกันสำหรับแต่ละ tag และ '*' หมายถึง 'wildcard' tag match

2) Levels

Logging ระดับต่างๆ ระดับที่มี: error, warning, info, debug, trace และ develop ปิด logging ใช้ off

3) Outputs

Output รองรับ 3 ประเภท: stdout, stderr, และ text file ตั้งค่า log file rotation ตามขนาดที่เขียนและจำนวนไฟล์ที่หมุนเวียน

4) Decorators

รายละเอียดเพิ่มเติมของ message เรียกว่า decorators:

  • time/timemillis/timenanos: เวลาและวันที่ปัจจุบัน (ISO-8601 format)
  • uptime/uptimemillis/uptimenanos: เวลาตั้งแต่เริ่มต้น JVM
  • pid: process identifier
  • tid: thread identifier
  • level: ระดับที่เชื่อมโยงกับ log message
  • tags: tag ที่เชื่อมโยงกับ log message

ตัวอย่างการใช้งาน

-Xlog
# Log ทุกข้อความระดับ info ไป stdout พร้อม uptime, levels, tags decorations

-Xlog:gc
# Log ข้อความที่มี tag 'gc' ระดับ info ไป stdout

-Xlog:gc,safepoint
# Log ข้อความ tag 'gc' หรือ 'safepoint' ทั้งคู่อยู่ระดับ info ไป stdout

-Xlog:gc=debug:file=gc.log:uptime,level,tags:filecount=5,filesize=10m
# GC debug logs ไปไฟล์ gc.log หมุนเวียน 5 ไฟล์ ขนาด 10MB ต่อไฟล์

Unified JVM Logging ทำให้ debug และ monitor JVM ง่ายขึ้นมาก โดยเฉพาะ GC และ performance tuning