11.3.3 실습 파일로 로그 기록 출력하기
1. 로그 설정 파일 log4j.xml에 다음 내용을 추가합니다.
코드 11-5 log4j.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/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="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n"/>
</layout>
</appender>
<!-- 파일에 출력하기 -->
➊
<appender name="monitor" class="org.apache.log4j.RollingFileAppender"> <param name="append" value="false"/> ➋ <param name="maxFileSize" value="10KB"/> ➌ <param name="maxBackupIndex" value="5"/> ➍ <param name="file" value="c:/logs/monitor.log"/> ➎
➏
<layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n"/> ➐ </layout>
➑
<filter class="org.apache.log4j.varia.LevelRangeFilter"> <param name="LevelMin" value="info"/> ➒ <param name="LevelMax" value="info"/> ➓ </filter>
</appender>
<!-- Application Loggers -->
<logger name="com.springmvc">
<level value="info"/>
<appender-ref ref="monitor"/> ⓫
</logger>
...
</log4j:configuration>