일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- log4j2
- eslint
- REACTJS
- Node
- migration
- log_bin
- regex
- REACT
- npm
- update
- Effective Java
- Regular expression
- java
- Effective Java 3/e
- current_date
- Express
- 퀵소트
- MySQL
- mysql 5.5
- git
- nodejs
- expire_logs_days
- Spring Batch
- Chunk
- spring
- upgrade
- spring cloud
- JavaScript
- 정규표현식
- Webpack
- Today
- Total
내 세상
[Java] Log4j 1.x to Log4j 2 Migration - Configuring Log4j 2 본문
https://logging.apache.org/log4j/2.x/manual/migration.html
Log4j – Migrating from Log4j 1.x
Copyright © 1999-2021 The Apache Software Foundation. All Rights Reserved. Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, and the Apache Logging project logo are trademarks of The Apache Software Foundation.
logging.apache.org
Log4j 1.x → Log4j 로 지칭
Log4j 2.x → Log4j2로 지칭
Configuring Log4j 2
Log4j2의 설정 문법은 Log4j와 다르지만, 대부분 동일한 기능을 사용할 수 있다.
System Property 설정은 ${foo}와 같은 문법을 사용함으로써, 다른 소스로 부터 lookup될 수 있도록 확장되었다. 자세한 Lookup에 대한 documentation의 링크는 아래와 같다. (https://logging.apache.org/log4j/2.x/manual/lookups.html)
예를 들어서, System Property lookup을 사용하기 위해서 Log4j에서는 catalina.base로 지칭되었지만, Log4j2에서는 ${catalina.base} 또는 ${sys:catalina.base}와 같이 사용된다.
Log4j는 Log4j2와 Xml Layout이 일부 다르게 구성되어있다. log4j-1.2-api 모듈은 Log4j1XmlLayout을 포함하고 있다. Log4j SimpleLayout은 PatternLayout의 "%level - %m%n" 형태와 유사하게 구성되어 있다. 그리고 Log4j TTCCLayout은 PatternLayout의 "%r [%t] %p %c %notEmpty{%ndc} - %m%n" 형태와 유사하게 구성되어있다.
Log4j PatternLayout과 EnhancedPatternLayout은 Log4j2에서 PatterLayout으로 사용할 수 있다.
Sample 1 - Simple Configuration Using a Console Appender
Log4j XML Configuration
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
</layout>
</appender>
<category name="org.apache.log4j.xml">
<priority value="info" />
</category>
<Root>
<priority value ="debug" />
<appender-ref ref="STDOUT" />
</Root>
</log4j:configuration>
Log4j2 XML Configuration
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
</Console>
</Appenders>
<Loggers>
<Logger name="org.apache.log4j.xml" level="info"/>
<Root level="debug">
<AppenderRef ref="STDOUT"/>
</Root>
</Loggers>
</Configuration>
'Language > Java' 카테고리의 다른 글
[Java] 정규 표현식 (Regex) Pattern, Matcher 사용 (0) | 2022.01.05 |
---|---|
[Java] 현재 시간을 yyyyMMddHHmmss String으로 추출하는 코드 (0) | 2022.01.04 |
[Java] Log4j 1.x to Log4j 2 Migration - Converting to the Log4j 2 API (0) | 2021.12.14 |
[Java] Effective Java 3/e - Item 12) toString을 항상 재정의하라 (0) | 2021.12.06 |
[Java] Effective Java 3/e - Item 9) try-finally 보다는 try-with-resoucres를 사용하라 (0) | 2021.12.03 |