一、概述
echo是Ant内置任务,用于向当前记录器和监听器(不覆盖的情况下是System.out)发送消息。通过设置level属性,可以控制消息按什么日志级别过滤。还可以输出到文件,可以选择追加或者覆盖文件,此时会忽略level属性。
二、属性
message:发送的消息。
file:写入消息的文件。
output:Ant1.8起。写入消息的资源。
append:是否追加到已经存在的文件,默认为false。此属性在设置了output属性时才生效,否则被忽略。
level:控制消息级别。可选值按级别降序为error、warning、info、verbose、debug。默认为warning。
encoding:Ant1.7起,编码格式,默认为“”,使用本地系统编码。
force:Ant1.8.2起,是否覆盖只读目标文件,默认为false。
紧跟在echo标签后的文本会作为输出的一部分,还要注意的是$,如果要输出$,则需要通过$$进行转义。
根据ant运行时的日志级别,消息可能会被忽略,-quiet只输出warning及以上级别消息,-verbose输出debug以上级别消息,-debug输出所有级别消息。默认情况下,输出info及以上级别消息。
三、简单示例
<project>
<echo>This is a longer message stretching over
two lines.
</echo>
<echo>
This is a longer message stretching over
three lines; the first line is a blank
</echo>
<echo message="This is error message." level="error" />
<echo file="runner.csh" append="false">#\!/bin/tcsh
java-1.3.1 -mx1024m ${project.entrypoint} $$*
</echo>
</project>