사용자 도구

사이트 도구


java:log4j:async

비동기 로깅

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
<log4j:configuration>
    <appender name="stdout" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{yyyy/MM/dd HH:mm:ss,SSS} [%t] %-5p %c %x - %m%n"/>
        </layout>
    </appender>
    <appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
        <param name="BufferSize" value="500"/>
        <param name="locationInfo" value="true"/>
        <appender-ref ref="stdout"/>
    </appender>
    <root>
        <priority value="error"></priority>
        <appender-ref ref="ASYNC"/>
    </root>
</log4j:configuration>
  • 주의 할 점들
    • 중복 로그가 발생하면, 로거에 additivity 속성을 false로 지정해야 한다.
    • The BufferSize parameter of the AsyncAppender defines the number of entries that will be stored in memory to let the actual appender catch up flushing them to their final destination. If this buffer fills up, the logging will switch to a synchronous mode until buffer space becomes available, potentially becoming a performance issue. Make sure this buffer is big enough, taking into account the IO speed and number of log entries generated by your application.
    • You can add the Blocking parameter to the AsyncAppender definition in your config file, if you set it to false (the default value is true) when the buffer fills up, the appender will discard log events until new buffer space becomes available. This can be unacceptable in applications where logging information is critical, but on the other hand can be very desirable where performance is a critical factor.
java/log4j/async.txt · 마지막으로 수정됨: 2013/04/11 10:12 저자 kwon37xi