1

I'd like to configure log4cxx via xml in order to roll my log file every minute. I tried with the following log4j.xml file but it seems to work only sometimes, randomly. I tried also with another xml file using TimeBasedRollingPolicy but it doesn't work. Any help would be appreciated.

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

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
    <appender name="appxRollingAppenderDaily" class="org.apache.log4j.rolling.RollingFileAppender">
        <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
            <param name="FileNamePattern" value="TimeBasedLog.%d{yyyy-MM-dd-HH-mm}.log"/>
            <param name="activeFileName" value="appxDailyLog.log"/>
        </rollingPolicy>

        <layout class="org.apache.log4j.PatternLayout">
             <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss,SSS} %x [%p] (%F:%L) %m%n"/>
        </layout>
        <param name="file" value="appxDailyLog.log"/>
        <param name="append" value="true"/>
    </appender>

    <root>
        <priority value="all" />
        <appender-ref ref="appxRollingAppenderDaily"/>
    </root>
</log4j:configuration>
m2fro
  • 21
  • 1
  • 4

1 Answers1

0

Try this:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> 
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> 

    <appender name="appxRollingAppenderDaily" class="org.apache.log4j.DailyRollingFileAppender"> 
      <param name="Threshold" value="ALL"/> 
      <param name="file" value="./appxDailyLog.log"/> 
      <param name="DatePattern" value="'.'yyyy-MM-dd" /> 
      <layout class="org.apache.log4j.PatternLayout"> 
<!--        <param name="ConversionPattern" value="%p %t %c - %m%n"/> --> 
<!--        <param name="ConversionPattern" value="%d{ISO8601} [%15.15t] %-5p %l - %m%n"/> --> 
<!--        <param name="ConversionPattern" value="%d{ISO8601} [%-8.8t] %-5p (%t) - %m%n"/> --> 
        <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss,SSS} %x [%p] (%F:%L) %m%n"/> 
      </layout> 
    </appender> 

    <root> 
      <priority value="ALL" /> 
      <appender-ref ref="appxRollingAppenderDaily"/> 
    </root> 

    </log4j:configuration> 
ingyhere
  • 11,818
  • 3
  • 38
  • 52
  • This should be the correct approach, but it does not work: every day it keeps on append logs to the same file, without creating a new file and renaming the old one. – m2fro Oct 31 '13 at 14:23
  • Check file system permissions. Can your app write to that directory and create files? – ingyhere Nov 01 '13 at 09:19
  • You could also try this approach: http://stackoverflow.com/questions/7103625/is-it-possible-to-have-a-new-file-for-each-new-day-with-log4cxx . – ingyhere Nov 01 '13 at 09:21
  • The app creates correctly the file if it does not exist, thus I think it's not a permission problem. I also tried the example you linked but the file does not roll. – m2fro Nov 18 '13 at 15:50