简体   繁体   English

在Ant中运行时,Eclipse控制台中的Log4j消息丢失

[英]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. 我一直在尝试使用Apache log4j进行日志记录,以便在Ant中运行时可以在Eclipse的控制台中正确显示,并且没有运气。 I have a working log4j.xml configuration that has a basic root logger, with a debug priority and a ConsoleAppender. 我有一个有效的log4j.xml配置,该配置具有基本的根记录器,调试优先级和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. 我已经验证了记录器的工作原理,因为如果我从项目中删除log4j.xml,Ant目标会抱怨它缺少log4j配置。 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. 将其切换回控制台,除了标准Ant输出之外,我对Eclipse控制台一无所知。

My JUnit tests, however, output log4j messages but I believe that is because I run them in batch and have those processes forked. 但是,我的JUnit测试输出log4j消息,但是我相信这是因为我批量运行它们并分叉了那些进程。

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. 如果我在命令行上运行完全相同的Ant脚本而未做任何更改,则会得到log4j输出,该输出期望与Ant输出交错。 I am running Ant 1.7.1 in Eclipse Helios on my Mac 10.6 Intel 64 machine. 我在Mac 10.6 Intel 64计算机上的Eclipse Helios中运行Ant 1.7.1。 I have verified this is also an issue on a Windows XP machine running Helios. 我已验证这也是运行Helios的Windows XP计算机上的问题。 I have tried setting "follow" to true in my console appender configuration and this has not helped. 我尝试在控制台附加程序配置中将“ follow”设置为true,但这没有帮助。

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. 我可以提供代码片段,但是就像我已经提到的那样,我已经证明log4j的配置正确,并且在类路径上拾取了log4j.xml,并且正在执行和输出日志记录。 It has something to do with how Ant integrates with Eclipse - anyone else experience this? 这与Ant与Eclipse的集成方式有关-其他人会遇到这种情况吗? Should this be something I submit to the Eclipse project? 这应该是我提交给Eclipse项目的东西吗?

I had a similar issue, Eclipse was not logging the junit messages or log4j. 我有一个类似的问题,Eclipse没有记录junit消息或log4j。 To get the junit log messages adding a formatter made the difference. 为了获得junit日志消息,添加了格式化程序就有所不同。 This seems to pass the log4j messages only once the test case is completed. 这似乎仅在测试用例完成后才传递log4j消息。

<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 log4j的问题是因为我在构建目录中没有配置文件,因此在ANT构建过程之后,我将其复制到构建路径中

<!--  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. 希望这对某人有帮助。

Java tasks executed through ant don't send there standard output and error to the main ant's output. 通过ant执行的Java任务不会将标准输出和错误发送到主ant的输出。

Have you looked at the output , error and i/o redirectors of the Ant Java task ? 您是否看过Ant Java任务outputerrori/o redirectors

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM