开发者

Log4j messages lost in Eclipse console when running in Ant

I've been trying to get logging with Apache log4j to appear correctly in Eclipse's console when running in Ant and am having no luck. I have a working log4j.xml configuration that has a basic root logger, with a debug priority and a ConsoleAppender. I have verified that the logger works because if I remove the log4j.xml from the project, the Ant target complains about it missing a log4j configuration. If I switch the appender to a file appender, all of the output properly goes to the file. Switching it back to the console, I get nothing to the Eclipse console except the standard Ant output.

My JUnit tests, however, output log4j messages but I believe that is because I run开发者_如何学运维 them in batch and have those processes forked.

If I run the exact same Ant script on the command line with no changes, I get the log4j output I expect interlaced with the Ant output. I am running Ant 1.7.1 in Eclipse Helios on my Mac 10.6 Intel 64 machine. I have verified this is also an issue on a Windows XP machine running Helios. I have tried setting "follow" to true in my console appender configuration and this has not helped.

I can provide code snippets, but like I've mentioned, I've proven that log4j is configured correctly and the log4j.xml is being picked up on the classpath and logging is being performed and outputted. It has something to do with how Ant integrates with Eclipse - anyone else experience this? Should this be something I submit to the Eclipse project?


Java tasks executed through ant don't send there standard output and error to the main ant's output.

Have you looked at the output, error and i/o redirectors of the Ant Java task?


I had a similar issue, Eclipse was not logging the junit messages or log4j. To get the junit log messages adding a formatter made the difference. This seems to pass the log4j messages only once the test case is completed.

<target name="junit" depends="copy_cfg">
        <junit printsummary="on" fork="false" haltonfailure="no">
            <classpath refid="MyProject.classpath" />
            <formatter type="xml" />
            <formatter type="plain" usefile="false" /> <!-- to screen -->
            <batchtest todir="${test.report.dir}">
                <fileset dir="${src.dir}">
                    <include name="**/*Test.java" />
                </fileset>
            </batchtest>
        </junit>
    </target>

The issue with the log4j was because I did not have the config file in the build directory, so after the ANT build process I copy it across to the build path

<!--  copy the config files for junit -->
<target name="copy_cfg" depends="compile">
    <copy file="log4j.xml" todir="${build.dir}" flatten="true"/>
    <copy file="config.txt" todir="${build.dir}" flatten="true"/>
</target>  

Hope this helps someone.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜