当我运行或在标签中时,多路复用日志将每个任务的输出混合在一起。我想要更容易阅读/ grokked的东西。
我尝试了以下方法,它们总比没有好,但仍然不是我想要的。以下回显了日志末尾的非交错日志输出,但它还首先具有两个任务的组合和混合输出。
有没有办法告诉ant ONLY输出到有问题的文件,不要将日志输出冒泡到调用者?
<parallel>
<ant target="task1" output=${log.dir}/task1.log"/>
<ant target="task2" output=${log.dir}/task2.log"/>
</parallel>
<loadfile property="task1" srcfile="${log.dir}/task1.log"/>
<loadfile property="task2" srcfile="${log.dir}/task2.log"/>
<echo>Results:
Task1: ${task1}
---
Task2: ${task2}
</echo>
答案 0 :(得分:4)
我有两种可能的解决方案:
我将选择第二种,因为它是最容易实现的,因为我可能会在以后以不同的方式解决这个问题(但可能遵循类似的模式)
主ant任务将使用record打开和关闭日志记录到build.log。并行之前它将禁用日志记录,让子ant记录到文件。完成后,ant将加载并回显输出。控制台输出继续混合,build.log被序列化。
这有点笨拙,但也不算太差。
<project name="antExperiments" default="para" basedir=".">
<!-- Logging Control -->
<property name="build.log.dir" location="${basedir}/logs"/>
<!-- - - - - - - - - - - - - - - - - -
macro: activate logging (defaults to ${build.log.dir}/build.log)
- - - - - - - - - - - - - - - - - -->
<macrodef name="start.log">
<attribute name="name" default="build"/>
<attribute name="dir" default="${build.log.dir}"/>
<attribute name="append" default="false"/>
<sequential>
<record action="start" append="@{append}" name="@{dir}/@{name}.log"/>
</sequential>
</macrodef>
<!-- - - - - - - - - - - - - - - - - -
macro: deactivate logging (defaults to ${build.log.dir}/build.log)
- - - - - - - - - - - - - - - - - -->
<macrodef name="stop.log">
<attribute name="name" default="build"/>
<attribute name="dir" default="${build.log.dir}"/>
<attribute name="append" default="false"/>
<sequential>
<record action="stop" append="@{append}" name="@{dir}/@{name}.log"/>
</sequential>
</macrodef>
<target name="clean">
<delete dir="${build.log.dir}"/>
<mkdir dir="${build.log.dir}"/>
</target>
<!-- - - - - - - - - - - - - - - - - -
target: main.init
Initialization for Top Level build - not used by subants
- - - - - - - - - - - - - - - - - -->
<target name="main.init">
<start.log/>
</target>
<!-- =================================
target: para
top level build runs 2 jobs in parallel producing interleaved hard to read
on to standard output and non interleaved more easily understood logging
to build.log
================================= -->
<target name="para" depends="main.init,clean">
<stop.log/> <!-- disable top level logging -->
<parallel threadcount="4" pollinterval="50">
<ant output="${build.log.dir}/proc1.log" target="proc1">
<property name="proc" value="proc1"/>
</ant>
<ant output="${build.log.dir}/proc2.log" target="proc2">
<property name="proc" value="proc2"/>
</ant>
</parallel>
<start.log/> <!-- enable top level logging -->
<!-- Non interleaved output -->
<loadfile property="p1" srcfile="${build.log.dir}/proc1.log"/>
<loadfile property="p2" srcfile="${build.log.dir}/proc2.log"/>
<echo>
--------------------------
BuildJob: proc1
OUTPUT: ******************
${p1}
**************************
--------------------------
BuildJob: proc2
OUTPUT: ******************
${p2}
**************************
BUILD LOG: ${build.log.dir}/build.log
</echo>
</target>
<target name="init">
<echo>Init called by ${proc}</echo>
</target>
<target name="proc1" depends="init">
<echo>PROC1.......................
</echo>
<exec dir="${basedir}" executable="cmd">
<arg line="/c dir \"/>
</exec>
</target>
<target name="proc2" depends="init">
<echo>PROC2..........2222222.......
</echo>
<exec dir="${basedir}" executable="cmd">
<arg line="/c dir \sandbox"/>
</exec>
</target>
</project>