본문으로 바로가기

Spring log4j 외부파일 저장 설정방법

category Backend/Spring 2019. 5. 9. 11:57
반응형
<?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/">
 
    <!-- Appenders -->
    <appender name="console"
        class="org.apache.log4j.ConsoleAppender">
        <param name="Target" value="System.out" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%-5p: %c - %m%n" />
        </layout>
    </appender>
 
    <!-- 날짜별 로그 파일 생성 -->
    <appender name="rollingFile"
        class="org.apache.log4j.DailyRollingFileAppender">
        <param name="File" value="D:/project_logs/log.log" />
        <param name="Append" value="true" /<!-- param name="MaxFileSize" value="100MB"/ --> <!-- param name="MaxBackupIndex" value="2"></param -->
        <param name="DatePattern" value="'.'yyyy-MM-dd" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d %p [%C{10}] %m %n" />
        </layout>
    </appender>
    
    <!-- 날짜별 로그 파일 생성(에러만) -->
    <appender name="errFile"
        class="org.apache.log4j.DailyRollingFileAppender">
        <param name="Threshold" value="ERROR" />
        <param name="File" value="D:/project_logs/errorLog.log" />
        <param name="Append" value="true" /<!-- param name="MaxFileSize" value="100MB"/ --> <!-- param name="MaxBackupIndex" value="2"></param -->
        <param name="DatePattern" value="'.'yyyy-MM-dd" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d %5p [%C{1}] %m %n" />
        </layout>
    </appender>
 
    <!-- Application Loggers -->
    <logger name="project.spring.travel">
        <level value="info" />
    </logger>
 
    <!-- 3rdparty Loggers -->
    <logger name="org.springframework.core">
        <level value="info" />
    </logger>
 
    <logger name="org.springframework.beans">
        <level value="info" />
    </logger>
 
    <logger name="org.springframework.context">
        <level value="info" />
    </logger>
 
    <logger name="org.springframework.web">
        <level value="info" />
    </logger>
 
    <!-- Root Logger -->
    <root>
        <!-- ===== Log4 로그 표시 수준 변경 ===== - 웹 페이지가 실행되는 동안 SQL구문이 로그에 출력되도록 하기 
            위해서는 로그의 표시 수준을 debug로 변경한다. - 로그는 높은 수준으로 설정할 수록 출력되는 수준에 대한 범위가 넓어진다. - 
            로그 표시 수준 TRACE (모든 로그 표시 > DEBUG > INFO > WARN > ERROR > FATAL (로그 표시 안함) -->
        <priority value="debug" />
        <appender-ref ref="console" />
        <appender-ref ref="rollingFile" />
        <appender-ref ref="errFile" />
    </root>
 
</log4j:configuration>
 



반응형

'Backend > Spring' 카테고리의 다른 글

Javax Mail 첨부파일  (0) 2019.09.11
3.1.1 파일업로드  (0) 2019.09.10
CKEDITOR 이미지 업로드 활성화  (4) 2019.04.29
Spring 에서 Scheduled 스케줄러 사용방법  (0) 2019.04.21
이클립스에서 톰캣 실행시 서버 오류  (0) 2019.04.19