未创建日志文件而是写入控制台

时间:2014-09-25 20:25:41

标签: java eclipse logging log4j

我正在为每次运行使用新的日志文件,如下所述: http://veerasundar.com/blog/2009/08/how-to-create-a-new-log-file-for-each-time-the-application-runs/

以下是我log4j.xml中的内容:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration PUBLIC
  "-//APACHE//DTD LOG4J 1.2//EN" "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">

<log4j:configuration debug="true"
    xmlns:log4j="http://jakarta.apache.org/log4j/">
    <appender name="toFile" class="com.ram.util.NewLogForEachRunFileAppender">
        <param name="file" value="./logs/log.txt" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern"
                value="[%t] %d{HH:mm:ss} %-5p %30.30C [%t] %30.30M %L - %m%n" />
        </layout>
    </appender>

    <root>
        <level value="ALL" />
        <appender-ref ref="toFile" />
    </root>

</log4j:configuration>

当我运行我的代码时,这就是我所看到的:

log4j: reset attribute= "false". log4j: Threshold ="null". log4j: Level value for root is [ALL]. log4j: root level set to ALL log4j: Class name: [com.ram.util.NewLogForEachRunFileAppender] log4j: Setting property [file] to [./logs/log.txt]. log4j: Parsing layout of class: "org.apache.log4j.PatternLayout" log4j: Setting property [conversionPattern] to [[%t] %d{HH:mm:ss} %-5p %30.30C [%t] %30.30M %L - %m%n]. log4j: setFile called: .\logs\log-1411675515571.txt, true log4j: setFile ended log4j: Adding appender named [toFile] to category [root]. [TestNG] Running: C:\Documents and Settings\ram0001\Local Settings\Temp\testng-eclipse-1777833329\testng-customsuite.xml

然后所有内容都写入控制台......我在这里做错了什么?

任何帮助??

0 个答案:

没有答案