1) pom에 slf4j, slf4j-class추가
2) logback.xml 추가
src/main/resources/logback.xml
<?xml version="1.0" encoding="UTF-8"?> <configuration> <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <layout class="ch.qos.logback.classic.PatternLayout"> <Pattern> %d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n </Pattern> </layout> </appender> <appender name="FILE" class="ch.qos.logback.core.FileAppender"> <file>/springframework_prj/logs/apache.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>gsb_log.%d{yyyy-MM-dd}.log</fileNamePattern> <minIndex>1</minIndex> <maxIndex>3</maxIndex> </rollingPolicy> <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> <maxFileSize>50MB</maxFileSize> </triggeringPolicy>
<append>true</append> <encoder> <pattern>%d [%thread] %-5level %logger - %msg%n</pattern> </encoder> </appender> <logger name="org.springframework.jdbc.core.StatementCreatorUtils"> <level value="debug" /> </logger> <logger name="org.springframework"> <level value="debug" /> </logger> <logger name="net.sf.ehcache"> <level value="debug" /> </logger> <logger name="com.my.framework"> <level value="debug" /> </logger> <root level="debug"> <appender-ref ref="CONSOLE" /> <appender-ref ref="FILE" /> </root> </configuration> |
3) sample 프로그램 작성
SampleController.java을 열어 Logger를 추가한다.
4) 브라우져을 열어 http://localhost:8080/FrameWork/sample을 입력
Eclipse의 로그 내용을 확인한다.
D:\springframework_prj\logs폴더의 log파일을 확인.