简体   繁体   English

ule子:如何在记录器中打印文件名?

[英]Mule: How to print the file name in logger?

I want to print the mule configuration file name, in the logger in the flow, how can I get it? 我要打印the子配置文件的名称,在流程的记录器中,如何获取它?

Suppose the configuration file name in test.xml, inside that a flow is having logger, which prints test.xml , how can I get this? 假设在test.xml中的配置文件名中,有一个流程包含logger,该文件打印test.xml ,我怎么能得到这个?

<flow name="filenameFlow">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/Hello" doc:name="HTTP"/>
    <logger message="#[app.name.toString()]" level="INFO" doc:name="Logger"/>
</flow>

Should print out the name of your application, in you case "test". 应打印出您的应用程序名称,以防万一。 This is not however the name of the xml file. 但是,这不是xml文件的名称。 #[flow.name] will give you the name of the flow currently executing. #[flow.name]将为您提供当前正在执行的流的名称。

[name.flow] is not correct one. [name.flow]不正确。

you should go with #[flow.name] which is the correct form. 您应该使用正确格式的#[flow.name] Don't mislead by your answers. 不要误解您的答案。

Thanks, 谢谢,

Try these expressions: 尝试以下表达式:

1) #[message.outboundProperties['originalFileName']] 1)#[message.outboundProperties ['originalFileName']]

2) #[header:originalFilename] 2)#[header:originalFilename]

I have done almost the same thing a few days ago. 几天前我做了几乎相同的事情。 Add a global element of type property placeholder , give location: mule-deploy.properties . 添加一个类型为property placeholderglobal element ,并指定location: mule-deploy.properties In logger, use ${config.resources} . 在记录器中,使用${config.resources} It will work if there is only one config file. 如果只有一个配置文件,它将起作用。

Just as @dlb explained, I am also wondering you may have better solution for your requirement, basically I am asuming that you want to make log more transparent, and easier to locate which flow caused any event/error. 就像@dlb解释的那样,我也想知道您是否可以为您的需求提供更好的解决方案,基本上我假设您想使日志更加透明,并更容易找到引起任何事件/错误的流程。

As such, it makes more sense to log flow name rather than the config file name, which may contain multiple flows.You can utilize the catagory in log component for this purpose: 因此,记录流名称而不是可能包含多个流的配置文件名称更有意义。您可以在日志组件中使用类别来实现此目的:

<logger level="INFO" category="${application-prefix}.myMainFlow" doc:name="Logger" message="#['payload is ---\n' + payload]"/>

In each and every log component (logs should be used in important places kind of milestones), input ${application-prefix}.flowName in catagory (property is used for reusing application's name in all logs, and flowName should be hardcoded), then you will find logs like below in runtime: 在每个日志组件中(应该在重要的里程碑中使用日志),在目录中输入$ {application-prefix} .flowName(属性用于在所有日志中重用应用程序的名称,并且应对flowName进行硬编码),然后您将在运行时中找到类似以下的日志:

INFO  2016-09-07 17:00:27,566 [[test].HTTP_Listener_Configuration.worker.01] com.myOrg.myApp.myMainFlow: payload is ---

Hello World 你好,世界

#[message.outboundproperties[originalFilename]]

试试这个表达式。

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

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