아키텍처와 함께

블로그 이미지
by gregorio
  • Total hit
  • Today hit
  • Yesterday hit

응용 시스템에서 로그를 남기기 위해 Logback을 사용하는 경우 Properties를 별도의 파일로 분리하여 설정이 가능하다.


■ logback.properties


#######################################################

# Logback propertiies                                  #

#######################################################

log.dir=d:/temp/logs/batchagent

log.level=DEBUG

app.log.name=agent_app

err.log.name=agent_error

max.history=7

max.log.file.size=50MB



Properties 파일은 key=value로 정의하면 된다.



■ logback.xml


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE xml>

<configuration scan="true" scanPeriod="60 seconds">


<property file="${user.dir}/conf/logback.properties" />


<!--  Application Log Appender -->

<appender name="applog" class="ch.qos.logback.core.rolling.RollingFileAppender">

<file>${log.dir}/${app.log.name}.log</file>

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">

<fileNamePattern>${log.dir}/%d{yyyy-MM, aux}/${app.log.name}.%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>

<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">

<maxFileSize>${max.log.file.size}</maxFileSize>

</timeBasedFileNamingAndTriggeringPolicy>

<maxHistory>${max.history}</maxHistory>

</rollingPolicy>


<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">

<charset>UTF-8</charset>

<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{50}.%M\(%line\) | %msg%n</pattern>

</encoder>

<filter class="ch.qos.logback.classic.filter.ThresholdFilter">

<level>${log.level}</level>

</filter>

</appender>



<!-- Error Log Appender -->

<appender name="errorlog" class="ch.qos.logback.core.rolling.RollingFileAppender">

<file>${log.dir}/${err.log.name}.log</file>

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">

<fileNamePattern>${log.dir}/%d{yyyy-MM, aux}/${err.log.name}.%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>

<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">

<maxFileSize>${max.log.file.size}</maxFileSize>

</timeBasedFileNamingAndTriggeringPolicy>

<maxHistory>${max.history}</maxHistory>

</rollingPolicy>


<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">

<charset>UTF-8</charset>

<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{50}.%M\(%line\) | %msg%n</pattern>

</encoder>

<filter class="ch.qos.logback.classic.filter.ThresholdFilter">

<level>WARN</level>

        </filter>

</appender>

<!-- SQL Log Appender -->

<appender name="sqllog" class="ch.qos.logback.core.rolling.RollingFileAppender">

<file>${LOG_DIR}/${SQL_LOG}.log</file>

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">

<fileNamePattern>${log.dir}/%d{yyyy-MM, aux}/${sql.log.name}.%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>

<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">

<maxFileSize>${max.log.file.size}</maxFileSize>

</timeBasedFileNamingAndTriggeringPolicy>

<maxHistory>${max.history}</maxHistory>

</rollingPolicy>


<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">

<charset>UTF-8</charset>

<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{50}.%M\(%line\) | %msg%n</pattern>

</encoder>

</appender>

<!-- End log appender -->


<logger name="org.springframework" level="${log.level}" additivity="false">

<appender-ref ref="applog" />

<appender-ref ref="errorlog" />

</logger>


<logger name="org.springframework.jdbc" additivity="false">

        <level value="WARN" />

<appender-ref ref="errorlog" />

    </logger>


<logger name="org.mybatis.spring" level="${log.level}" additivity="false">

<appender-ref ref="applog" />

<appender-ref ref="errorlog" />

</logger>


<logger name="io.netty" level="${log.level}" additivity="false">

<appender-ref ref="applog" />

<appender-ref ref="errorlog" />

</logger>

<logger name="org.apache.http" level="${log.level}" additivity="false">

<appender-ref ref="applog" />

<appender-ref ref="errorlog" />

</logger>


<logger name="org.apache.ibatis" level="${log.level}" additivity="false">

<appender-ref ref="applog" />

<appender-ref ref="errorlog" />

</logger>


<logger name="org.quartz" level="${log.level}" additivity="false">

<appender-ref ref="applog" />

<appender-ref ref="errorlog" />

</logger>


<!-- SQL base level -->

<logger name="java.sql" additivity="false">

<level value="WARN" />

<appender-ref ref="errorlog" />

</logger>


<!--JDBC SQL Query Print logging level-->

<logger name="jdbc.connection" level="OFF" additivity="false"> 

<appender-ref ref="errorlog" />

</logger>


    <logger name="jdbc.resultset" level="OFF" additivity="false"> 

<appender-ref ref="errorlog" />

    </logger>


<logger name="jdbc.audit" level="OFF" additivity="false"> 

<appender-ref ref="errorlog" />

</logger>


<logger name="jdbc.sqltiming" level="OFF" additivity="false"> 

<appender-ref ref="sqllog" />

    </logger>


<!-- want to log sql result, set level info  -->

<logger name="jdbc.resultsettable" level="INFO" additivity="false"> 

<appender-ref ref="sqllog" />

</logger>

<logger name="jdbc.sqlonly" level="DEBUG" additivity="false">

<appender-ref ref="sqllog" />

</logger>


<root level="${log.level}">

<appender-ref ref="console" />

<appender-ref ref="errorlog" />

</root>

</configuration>

 

logback.xml 파일에 properties 파일을 <property file="" />를 이용하여 Properties 파일을 읽는다.


Properties 파일에 정의되어 있는 Property를 사용할 때 ${property key}로 사용하면 된다.

AND

ARTICLE CATEGORY

분류 전체보기 (56)
Spring Framrwork (33)
Linux (1)
APM (1)
Java (8)
python (0)
ant (1)
chart (1)
OS (1)
tomcat (1)
apache (1)
database (0)

RECENT ARTICLE

RECENT COMMENT

CALENDAR

«   2025/01   »
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

ARCHIVE

LINK