------

[ AD ] Port Monitor ( Try to use a Best WebSite Monitoring Tool )

------

 

Log4j 사용하기 ( in MVC controller )

출처 :  http://zjhzxhz.com/2014/06/integrate-spring-mvc-with-log4j/

 

1. Log4j Library 프로젝트에 추가하기

1) Log4j-1.x.x.jar를 libray에 복사

2) Maven을 사용해서 자동 다운로드

 pom.xml

 <dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>

 

2. log4j.properties구성

 properties

 # LOG4J configuration
log4j.rootLogger=INFO, console, file
# Console Logger
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=[%p] %d %c %x - %m%n

# File Logger
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.File=${catalina.home}/logs/oes
log4j.appender.file.DatePattern='-'yyyy-MM-dd'.log'
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=[%p] %d %c %x - %m%n

 

3. 호출(사용법)

 Controller

 public class AAAController
{
    private Logger logger = Logger.getLogger(AAAController.class);
    public loginAction()
    {
        logger.info( String.format("name[%s]",new Object[] {name} );
    }
}

 

'0.일반개발' 카테고리의 다른 글

home.jsp 깨짐  (0) 2015.06.23
Exit Code=13  (0) 2015.06.12
Spring 4 MVC Hello World Tutorial using maven  (0) 2015.06.05
HttpServlet not found  (0) 2015.06.05
Spring Boot 프로젝트 생성 예제  (0) 2015.05.13

+ Recent posts