log4j
log4j는 사용자 정의를 기록합니다.
수색…
구성 파일
구성
Log4j 구성 파일은 다음 형식 중 하나 일 수 있습니다.
- JSON
- YAML
- 속성 (텍스트 파일)
- XML
구성 검색
- Log4j는
log4j.configurationFile시스템 등록 정보를 검사하고, 설정되어 있으면 구성로드를 시도합니다. - 시스템 등록 정보가 설정되어 있지 않으면 log4j는 classpath에
log4j2-test.properties를 찾습니다. - 그런 파일이 없으면 log4j는 classpath에
log4j2-test.yaml또는log4j2-test.yml. - 그런 파일이 없으면 log4j는 클래스 경로에
log4j2-test.json또는log4j2-test.jsn. - 그런 파일이 없으면 logj4는 클래스 경로에서
log4j2-test.xml을 찾습니다. - 테스트 파일을 찾을 수 없으면 log4j는 클래스 경로에서
log4j2.properties를 찾습니다. - 등록 정보 파일을 찾을 수 없으면 log4j는 classpath에
log4j2.yaml또는log4j2.yml을 찾습니다. - YAML 파일을 찾을 수 없으면 log4j는 클래스 경로에서
log4j2.json또는log4j2.jsn을 찾습니다. - JSON 파일을 찾을 수없는 경우 log4j는 classpath에
log4j2.xml을 찾으려고 시도합니다. - 구성 파일을 찾을 수 없으면 DefaultConfiguration이 사용됩니다. 이로 인해 로깅 출력이 콘솔로 이동합니다.
XML 구성
XML 예제
아래의 구성은 두 개의 애펜더 (로그 출력)를 구성합니다. 첫 번째는 표준 시스템 출력 (콘솔)에 로그하고 다른 로그는 파일에 기록합니다. 이 예제에서 파일의 위치는 구성 (appender file )에서 정적으로 설정하거나 maven 필터링 기능 ( <Property name="APPENDER"> )을 통해 동적으로 설정할 수 있습니다. 로그 인 파일은 하루에 압축됩니다. 로그 라인 형식 Conversion Pattern 은 변수로 설정됩니다.
<?xml version="1.0" encoding="UTF-8"?>
<!-- 'status' sets log level for parsing configuration file itself -->
<Configuration status="INFO">
<Properties>
<!-- Sets variable PID, if it's not present in log4j context will take value as below: -->
<Property name="PID">????</Property>
<!-- Sets variable 'LOG_PATTERN', defining how log line will look like -->
<Property name="LOG_PATTERN">%clr{%d{yyyy-MM-dd HH:mm:ss.SSS}}{faint} %clr{%5p} %clr{${sys:PID}}{magenta} %clr{%X{usr}}{green} %clr{---}{faint}%clr{[%15.15t]}{faint} %clr{%-40.40c{1.}:%l}{cyan} %clr{:}{faint} %m%n%wEx</Property>
<!-- LOG_DIR may be set by maven filtering feature: -->
<Property name="LOG_DIR">@logging.path@</Property>
<!-- APPENDER may be set by maven filtering feature, to set 'console' or 'file' appender: -->
<Property name="APPENDER">@logging.default.appender@</Property>
</Properties>
<Appenders>
<!-- Sets console output: -->
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="${LOG_PATTERN}"/>
</Console>
<!-- Sets output to file, and names it 'file' -->
<RollingRandomAccessFile append="true" fileName="${LOG_DIR}/log4j2.log"
filePattern = "${LOG_DIR}/log4j2.%d{yyyy-MM-dd}.nr%i.log.gz" name="file">
<PatternLayout>
<Pattern>${LOG_PATTERN}</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy />
</Policies>
</RollingRandomAccessFile>
</Appenders>
<Loggers>
<!-- Sets debug for Class 'com.example.package.Clazz', and attaches to file 'file' -->
<Logger name="com.example.package.Clazz" level="debug">
<AppenderRef ref="file"/>
</Logger>
<!-- Sets 'info' for package 'org.springframework' -->
<Logger name="org.springframework" level="info" />
<Root level="WARN">
<AppenderRef ref="${APPENDER}"/>
</Root>
</Loggers>
</Configuration>
Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow