티스토리 뷰



logback 을 활용해서 로깅을 기록하다보면 멀티인스턴스 환경, 즉 하나의 웹서버로 다수의 JVM 인스턴스 상황에서 하나의 파일에 로깅을 해야 할 경우가 발생한다. 이럴 때를 위해 logback 에서는 prudent 모드를 지원하는데, 파일 락(lock) 기반이므로 성능에 영향을 미친다고 logback 사이트에 명시되어 있다. 


다만 실제로 적용을 해보니 prudent 를 true 로 한 경우에도 JVM 인스턴스 갯수만큼 지속적으로 로깅파일이 생성되어 한참을 원인을 찾느라 고생을 했는데. RollingFileAppender 의 경우 prudent 를 true 로 사용하는 경우 파일 생성시에 아예 index 를 달아서 생성되게끔 구성되어 있기 때문에 RollingFileAppender 기반으로 prudent 모드를 true 로 사용하는 경우는 아래와 같이 주의해야 할 점이 있다.


Property NameTypeDescription
fileStringSee FileAppender properties.
appendbooleanSee FileAppender properties.
encoderEncoderSee OutputStreamAppender properties.
rollingPolicyRollingPolicyThis option is the component that will dictate RollingFileAppender's behavior when rollover occurs. See more information below.
triggeringPolicyTriggeringPolicyThis option is the component that will tell RollingFileAppender when to activate the rollover procedure. See more information below.
prudentbooleanFixedWindowRollingPolicy is not supported in prudent mode.

RollingFileAppender supports the prudent mode in conjunction with TimeBasedRollingPolicy albeit with two restrictions.

  1. In prudent mode, file compression is not supported nor allowed. (We can't have one JVM writing to a file while another JVM is compressing it.)
  2. The file property of FileAppender cannot be set and must be left blank. Indeed, most operating systems do not allow renaming of a file while another process has it opened.
See also properties for FileAppender.


즉, file 속성을 명시하면 특정 O/S 의 경우는 파일명 rename 에 제한이 있어 정상적으로 동작하지 않을 수 있다는 내용으로 내 경우는 AIX 에서 weblogic 12c 를 사용할 경우 하나의 파일이 아닌 다수의 파일에 로깅이 되는 문제가 있었고, file 속성을 삭제하고 rollingPolicy 속성 하위의 fileNamePattern 만으로 문제를 해결했다.


뭐든 공식문서를 꼼꼼히 읽어야 하는데.. 시간없이 급하게 일을 하니 이런일이 생긴다.


참고로 설정은 다음과 같다.


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

        <!-- <file>${LOG_HOME}/summary.log</file> -->

<prudent>true</prudent>

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

            <!-- rollover daily -->

            <fileNamePattern>${LOG_HOME}/summary.log.%d{yyyyMMdd}.%i</fileNamePattern>

            <maxHistory>10</maxHistory>

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

                <!-- or whenever the file size reaches 100MB -->

                <maxFileSize>100MB</maxFileSize>

            </timeBasedFileNamingAndTriggeringPolicy>

        </rollingPolicy>


        <encoder>

            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS}|%msg%n</pattern>

        </encoder>

    </appender>  



댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
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
글 보관함