0

I am trying to configure log4j using xml. I am using log4j1.2.13.jar and apache-log4j-extras-1.2.17.jar.

below is the xml.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

  <appender name="R" class="org.apache.log4j.rolling.RollingFileAppender">
    <param name="File" value="${LOG_FILE}"/> 
    <param name="append" value="true"/>
    <param name="encoding" value="UTF-8"/>    
    <layout class="org.apache.log4j.TTCCLayout">
      <param name="ContextPrinting" value="true"/>
      <param name="ThreadPrinting" value="true"/>
      <param name="DateFormat" value="MM/dd/yyyy HH:mm:ss"/>
    </layout>
    <rollingPolicy class="org.apache.log4j.rolling.FixedWindowRollingPolicy">
        <param name="FileNamePattern" value="${LOG_FILE}%i.gz" />           
    </rollingPolicy>
    <triggeringPolicy class="org.apache.log4j.rolling.SizeBasedTriggeringPolicy">
        <param name="MaxFileSize" value="${LOG_FILESIZE_LIMIT}"/>
    </triggeringPolicy>
   </appender>

 <root>
    <priority value ="DEBUG"/>
    <appender-ref ref="R"/>    
  </root>

</log4j:configuration>

But its not generating logs for the project. Below are the errors ::

log4j:WARN Continuable parsing error 15 and column 78
log4j:WARN Element type "rollingPolicy" must be declared.
log4j:WARN Continuable parsing error 18 and column 79
log4j:WARN Element type "triggeringPolicy" must be declared.
log4j:WARN Continuable parsing error 21 and column 15
log4j:WARN The content of element type "appender" must match "(errorHandler?,param*,layout?,filter*,appender-ref*)".
log4j:WARN Please set a rolling policy for the RollingFileAppender named 'R'
level::: 7
log4j:ERROR No output stream or file set for the appender named [R].

Please help me to solve the issue.

Anjali
  • 1,623
  • 5
  • 30
  • 50

2 Answers2

0

Try using

org.apache.log4j.RollingFileAppender

instead of

org.apache.log4j.rolling.RollingFileAppender 

and check this thread for more Rolling issue log4J

Community
  • 1
  • 1
  • before i was using org.apache.log4j.RollingFileAppender only and it was working ..but now i want to zip the log files thats why i am trying to use org.apache.log4j.rolling.RollingFileAppender. I want to zip the files based on the size. – Anjali Jun 09 '14 at 08:22
  • Did you tried http://logging.apache.org/log4j/extras/ – Abubakr Elkabany Jun 26 '14 at 11:35
0

According to the answer here: https://stackoverflow.com/a/13037467/874672

You need to use a log4j.jar version newer than log4j-1.2.14.jar.

Community
  • 1
  • 1
Matt_Bro
  • 14,062
  • 2
  • 28
  • 41