Mule: How to print the file name in logger?

大兔子大兔子 提交于 2019-12-12 02:39:30

问题


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>

回答1:


[name.flow] is not correct one.

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

Thanks,




回答2:


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.




回答3:


Try these expressions:

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

2) #[header:originalFilename]




回答4:


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.




回答5:


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




回答6:


#[message.outboundproperties[originalFilename]]

Try this expression.



来源:https://stackoverflow.com/questions/39200764/mule-how-to-print-the-file-name-in-logger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!