티스토리 뷰

Study

log4j(로그포제이) 관련

메디츠 2024. 3. 15. 16:08
반응형

16년 9월 기준.

 

compile "org.apache.logging.log4j:log4j-api:${version.log4j}"

compile "org.apache.logging.log4j:log4j-core:${version.log4j}"

compile "org.apache.logging.log4j:log4j-jcl:${version.log4j}"

// commons-logging bridge

compile "org.apache.logging.log4j:log4j-1.2-api:${version.log4j}"

// 1.x version bridge

compile "org.apache.logging.log4j:log4j-slf4j-impl:${version.log4j}"

// slf4j bridge

 

https://logging.apache.org/log4j/2.x/maven-artifacts.html

 

Appinit.java

@Override

protected void registerDispatcherServlet(ServletContext servletContext) {

super.registerDispatcherServlet(servletContext);

 

servletContext.setInitParameter("log4jConfigLocation", "/WEB-INF/config/log4j.properties");

servletContext.addListener(new Log4jConfigListener());

}

// web.xml로 추가해도 된다.

 

log4j.properties(xml도 가능)

# Log4j Setting file

log4j.rootLogger=INFO, console, logfile

 

# Console log

log4j.appender.console=org.apache.log4j.ConsoleAppender

log4j.appender.console.layout=org.apache.log4j.PatternLayout

log4j.appender.console.layout.ConversionPattern=%-5p %l - %m%n

 

# Daily file log

log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender

log4j.appender.logfile.File=/logs/log.log

log4j.appender.logfile.DatePattern='.'yyyy-MM-dd

log4j.appender.logfile.layout=org.apache.log4j.PatternLayout

log4j.appender.logfile.layout.ConversionPattern=[%d{HH:mm:ss}][%-5p](%F:%L) - %m%n

 

# log level and appender

log4j.logger.com.real=DEBUG, console

log4j.logger.com.real.Test=INFO, logfile

 

The main package in version 1 is org.apache.log4j, in version 2 it is org.apache.logging.log4j

// 주의해서 사용.

 

로그찍을때 주의!

log4j

logger.info("path - "+REQUEST_XML_PATH);

logger.info("path - ", REQUEST_XML_PATH); {} , 사용불가.

 

slf4j

logger.info("path - "+REQUEST_XML_PATH);

logger.info("path - {}",REQUEST_XML_PATH);

logger.info("path - ", REQUEST_XML_PATH);

 

log4j:WARN No appenders could be found for logger (org.apache.cayenne.conf.DefaultConfiguration).

log4j:WARN Please initialize the log4j system properly.

WEB-INF/classss/경로에 log4j.properties 생성

<context-param>

<param-name>log4jConfigLocation</param-name>

<param-value>/WEB-INF/classes/properties/log4j.properties

</param-value>

</context-param>

 

log4j 로그레벨. trace>debug>info>warn>fatal. debug, info 주로 사용.

 

debug 로그 안나옴

<logger name="com.project.controller">

<level value="info" />

</logger>

// logger 레벨 확인

 

 

반응형

'Study' 카테고리의 다른 글

javascript(자바스크립트) encode(인코드)  (0) 2024.03.15
Java(자바) domain(도메인) IP(아이피) 확인  (0) 2024.03.15
Java(자바) XML request  (0) 2024.03.15
git(깃) 관련  (0) 2024.03.15
MySQL(마이에스큐엘) 관련  (1) 2024.03.15
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/12   »
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
29 30 31
글 보관함