Configuring RollingFileAppender in log4j

前端 未结 8 1319
谎友^
谎友^ 2020-12-01 01:43

I\'m working on a set of web services and we\'d like to have a daily rotated log.

I\'m trying to get org.apache.log4j.rolling.RollingFileAppender from t

相关标签:
8条回答
  • 2020-12-01 02:42

    Faced more issues while making this work. Here are the details:

    1. To download and add apache-log4j-extras-1.1.jar in the classpath, didn't notice this at first.
    2. The RollingFileAppender should be org.apache.log4j.rolling.RollingFileAppender instead of org.apache.log4j.RollingFileAppender. This can give the error: log4j:ERROR No output stream or file set for the appender named [file].
    3. We had to upgrade the log4j library from log4j-1.2.14.jar to log4j-1.2.16.jar.

    Below is the appender configuration which worked for me:

    <appender name="file" class="org.apache.log4j.rolling.RollingFileAppender">
            <param name="threshold" value="debug" />
            <rollingPolicy name="file"
                class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
                <param name="FileNamePattern" value="logs/MyLog-%d{yyyy-MM-dd-HH-mm}.log.gz" />
                <!-- The below param will keep the live update file in a different location-->
                <!-- param name="ActiveFileName" value="current/MyLog.log" /-->
            </rollingPolicy>
    
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" value="%5p %d{ISO8601} [%t][%x] %c - %m%n" />
            </layout>
    </appender>
    
    0 讨论(0)
  • 2020-12-01 02:45

    You have a bad package name

    org.apache.log4j.rolling.RollingFileAppender 
    

    The correct one is:

    org.apache.log4j.RollingFileAppender 
    
    0 讨论(0)
提交回复
热议问题