简体   繁体   中英

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?

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>

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.

[name.flow] is not correct one.

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

Thanks,

Try these expressions:

1) #[message.outboundProperties['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 . In logger, use ${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.

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

#[message.outboundproperties[originalFilename]]

试试这个表达式。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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