반응형
2021.12.14 - [OpenSource/log4j&slf4j] - log4j2 보안 취약성 발생!
log4j.xml로 먼저 설정이 되어있다는 가정하에 진행을 해보도록 하겠습니다. 또한 maven 기반!!
당연히! SLF4J 를 사용하겠죵~~
룰루랄라 신나는 로그포제이 투! 설정 해보기! 두둥~
log4j.xml과 log4j2.xml이 필요 합니다.
log4j2 에 필요한 것!!!
1) pom.xml 에서의 설정!
2) log4j2.xml의 설정!
3) pojo단에서의 쓰임새!
요정도가 되겠네요! ㅎㅎㅎ
<< pom.xml 설정 >>
기본적으로 log4j설정은 아래와 같이 되어있습죠! <!-- Logging --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${org.slf4j-version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>jcl-over-slf4j</artifactId> <version>${org.slf4j-version}</version> <scope>runtime</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${org.slf4j-version}</version> <scope>runtime</scope> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.15</version> <exclusions> <exclusion> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> </exclusion> <exclusion> <groupId>javax.jms</groupId> <artifactId>jms</artifactId> </exclusion> <exclusion> <groupId>com.sun.jdmk</groupId> <artifactId>jmxtools</artifactId> </exclusion> <exclusion> <groupId>com.sun.jmx</groupId> <artifactId>jmxri</artifactId> </exclusion> </exclusions> <scope>runtime</scope> </dependency> |
log4j2 셋팅!!
<!-- log4j2 setting --> <!-- Binding for Log4J --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-slf4j-impl</artifactId> <version>${log4j2.version}</version> </dependency> <!-- Log4j API and Core implementation required for binding --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>${log4j2.version}</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>${log4j2.version}</version> </dependency> 출처 : 외국인 형이 정리를 잘해놨네요 감사! http://whoopdicity.blogspot.kr/2014/04/configuring-slf4j-with-log4j2-using.html |
<< log4j2.xml 설정 >>
<?xml version="1.0" encoding="UTF-8"?> <configuration status="WARN"> <appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" /> </Console> </appenders> <loggers> <root level="debug"> <appender-ref ref="Console" /> </root> </loggers> </configuration> |
<< POJO단 쓰임새 >>
import org.apache.logging.log4j.Logger; private static final Logger logger = LogManager.getLogger(LogInController.class); logger.info() or logger.debug() 등등 사용!! |
<< 결과!! >>
참고 사이트 : http://logging.apache.org/log4j/2.x/manual/index.html
- END -
반응형
'OpenSource > log4j&slf4j' 카테고리의 다른 글
log4j2 보안 취약성 발생! (0) | 2021.12.14 |
---|---|
통합 log 관련 테스트- AsyncAppender (0) | 2014.03.13 |
[Local] 통합log 처리 방법, log4j, SocketAppender + SocketHubAppender (3) | 2014.02.18 |
[log4j viewer] otroslogviewer (SocketHub 사용) (0) | 2014.02.07 |
log4j를 알아보자 (0) | 2014.01.09 |