DailyRollingFileAppender not work

Sonrobby picture Sonrobby · Oct 26, 2012 · Viewed 15.7k times · Source

I use Log4j to write some log my program. I find and read many question and answer in this site, but i can't solve my problem.

Here my code:

1. log4j.xml

<appender name="rollingfileAppender" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="append" value="true"/>
    <param name="file" value="logs/process.log"/>
    <param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
    <layout class="org.apache.log4j.PatternLayout">
       <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss:SSS} %-5p [%c{1}] %m%n"/>
    </layout>
</appender>
<root>
    <level value="DEBUG"/>
    <appender-ref ref="rollingfileAppender"/>
    <appender-ref ref="stdout"/>
</root>

2. My java code

package TestPacket;

import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;


public class TestLog4jXML {
    static Logger logger = org.apache.log4j.Logger.getLogger(TestLog4jXML.class.getName());
    public TestLog4jXML() {
    }
    public static void main(String[] args) {
        try {
            DOMConfigurator.configure("log4j1.xml");
            logger.trace("Entering application.");
            logger.debug("Debug");
            logger.info("info");
            logger.warn("warn");
            logger.error("error");
            logger.fatal("fatal");
            lungtng();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void lungtng()
    {
        logger.fatal("some text here");
        logger.info("hello picaso");
    }
}

And i run my program, with eclipse, windows os. But the log file name only: process.log not in daily format: process.log.yyyy-MM-dd-HH

Who can explain this to me?

Answer

atom88 picture atom88 · Sep 26, 2014