【发布时间】:2016-11-10 19:37:47
【问题描述】:
我有一个骆驼应用程序,它在路由构建器中定义了许多路由。其中一条路线有一个 xslt 管道,我想在 splunk 中记录其性能。日志格式需为:
PerformanceDetailResultMs=<numberOfMsTheXsltsTook>
我已尝试执行以下操作但不起作用,因为 System.currentTimeMillis() 的结果由 spring 保留,因此当 routeBuilder 类执行时,当时提取的任何值都会保留:
from(direct:somewhere)
//... other things
.setProperty(START_TIME, simple(Long.toString(System.currentTimeMillis()), Long.class))
.to("xslt:templates/bop1.xslt?saxon=true")
.to("xslt:templates/bop2.xslt?saxon=true")
.to("xslt:templates/bop3.xslt?saxon=true")
.to("xslt:templates/bop4.xslt?saxon=true")
.to("xslt:templates/bop7.xslt?saxon=true")
.to("xslt:templates/bop8.xslt?saxon=true")
.to("xslt:templates/bop9.xslt?saxon=true")
.to("xslt:templates/premGen1.xslt?saxon=true")
.to("xslt:templates/premGen2.xslt?saxon=true")
.setProperty(END_TIME, simple(Long.toString(System.currentTimeMillis()), Long.class))
.log("PerformanceDetailResultMs=${exchangeProperty." + END_TIME + "} - ${exchangeProperty." + START_TIME + "}")
//... other things
START_TIME 和 END_TIME 变量只是私有静态字符串,希望它们可以被重复使用。此代码不起作用,因为 START_TIME 和 END_TIME 在 routeBuilder 实例化上设置并由 spring 静态保留。您不会每次通过路线都获得新的时间戳。
什么是正确的“骆驼方式”来计时操作子集,以便我可以输出如下日志语句:
PerformanceDetailResultMs=489234
【问题讨论】:
标签: logging apache-camel