Java 9는 JVM 내부 구성 요소 전반에 걸쳐 상세한 수준 제어가 가능한 통합 로깅 시스템(Unified Logging System)을 도입했습니다. 새로운 명령줄 옵션인 -Xlog 하나만으로 모든 로깅 설정을 일관되게 관리할 수 있으며, 이를 통해 복잡한 시스템 수준의 JVM 구성 요소에서 발생하는 문제에 대한 근본 원인 분석(RCA, Root Cause Analysis)을 손쉽게 수행할 수 있습니다.
-Xlog 옵션은 JVM의 모든 로깅 구성 요소를 제어하는 데 사용됩니다. -Xlog의 인자(arguments)는 다음 규칙을 따릅니다.
- 여러 개의 인자를 지정하면 명령줄에 나타난 순서대로 순차적으로 적용됩니다.
- 마지막 설정 우선 규칙: 동일한 출력 대상에 여러 인자가 지정되면, 주어진 순서대로 앞선 설정을 덮어씁니다(override).
-Xlog:disable을 지정하면 모든 로깅이 꺼지며, 경고(warnings)와 오류(errors)를 포함해 로깅 프레임워크의 기존 설정이 모두 초기화됩니다.
기본 문법(Syntax)
-Xlog:tag[*][=level][:output[:decoration[:output-option]]],tag...
-Xlog:help를 실행하면 -Xlog의 사용법과 함께 사용 가능한 태그(tags), 레벨(levels), 데코레이터(decorators) 목록과 예제 명령줄을 확인할 수 있습니다.
1) 태그(Tags)
로그 메시지가 출력될 때 JVM은 해당 메시지를 os, gc, modules 같은 식별 이름으로 구성된 태그 집합과 연결합니다. 태그별로 서로 다른 설정을 적용할 수 있으며, '*'는 '와일드카드(wildcard)' 매칭을 의미합니다.
2) 레벨(Levels)
로깅은 여러 단계의 레벨로 수행할 수 있으며, 사용 가능한 레벨은 error, warning, info, debug, trace, develop입니다. 로깅을 비활성화하려면 off를 사용합니다.
3) 출력(Outputs)
출력은 stdout, stderr, 텍스트 파일 세 가지 유형을 지원합니다. 파일 출력 시에는 기록된 크기와 회전할 파일 수를 기준으로 로그 파일 로테이션(rotation)을 설정할 수 있습니다.
4) 데코레이터(Decorators)
데코레이터는 로그 메시지에 부가 정보를 덧붙이는 요소로, 주요 항목은 다음과 같습니다.
- time / timemillis / timenanos: 현재 날짜와 시간 (ISO-8601 형식)
- uptime / uptimemillis / uptimenanos: JVM 시작 이후 경과 시간
- pid: 프로세스 식별자
- tid: 스레드 식별자
- level: 해당 로그 메시지의 레벨
- tags: 해당 로그 메시지와 연관된 태그
-Xlog:help 실행 결과
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, 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, unload, 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. (Messages tagged with both 'gc' and 'safepoint' will not be logged.)
주요 활용 예시 정리
- -Xlog: 모든 메시지를 info 레벨로 stdout에 출력하며, uptime, levels, tags 데코레이터를 기본으로 사용합니다. (-Xlog:all=info:stdout:uptime,levels,tags와 동일)
- -Xlog:gc: gc 태그가 붙은 메시지를 info 레벨로 stdout에 기본 데코레이터와 함께 출력합니다.
- -Xlog:gc,safepoint: gc 또는 safepoint 태그가 붙은 메시지를 info 레벨로 stdout에 출력합니다. 단, 두 태그가 모두 붙은 메시지는 로깅되지 않습니다.