Mule: How to print the file name in logger?

2019-09-13 10:22发布

I want to print the mule configuration file name, in the logger in the flow, how can I get it?

Suppose the configuration file name in test.xml, inside that a flow is having logger, which prints test.xml, how can I get this?

<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>

6条回答
\"骚年 ilove
2楼-- · 2019-09-13 10:34

Try these expressions:

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

2) #[header:originalFilename]

查看更多
姐就是有狂的资本
3楼-- · 2019-09-13 10:36

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.

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:

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

Hello World

查看更多
放我归山
4楼-- · 2019-09-13 10:44
#[message.outboundproperties[originalFilename]]

Try this expression.

查看更多
老娘就宠你
5楼-- · 2019-09-13 10:45

Should print out the name of your application, in you case "test". This is not however the name of the xml file. #[flow.name] will give you the name of the flow currently executing.

查看更多
我欲成王,谁敢阻挡
6楼-- · 2019-09-13 10:51

I have done almost the same thing a few days ago. Add a global element of type property placeholder, give location: mule-deploy.properties. In logger, use ${config.resources}. It will work if there is only one config file.

查看更多
相关推荐>>
7楼-- · 2019-09-13 10:52

[name.flow] is not correct one.

you should go with #[flow.name] which is the correct form. Don't mislead by your answers.

Thanks,

查看更多
登录 后发表回答