Dynamic log file path in mule

2019-08-07 03:52发布

I m trying to change log file path in mule dynamically I have set the system property in an expression component but since log4j2.XML decodes the value at compile time itself it is not getting reflected I have even set monitor interval in log4j.XML but it is not working how to achieve dynamic file path?

2条回答
该账号已被封号
2楼-- · 2019-08-07 04:38

If you want run-time changes to logging, you'll need to initialise a new Log4J logger in a Java class. Otherwise using default Mule logging functionality requires you restarting/re-initialising the Mule application.

查看更多
男人必须洒脱
3楼-- · 2019-08-07 04:44

To make your log file name and path dynamically is to set the path in environment variable.
In the log4j2.xml, you can do something like the following :-

<RollingFile name="RollingFile" fileName="${sys:CustomapPath}/${sys:CustomapplicationName}_WARN.log"
filePattern="${sys:CustomapPath}/test/${sys:CustomapplicationName}-%d{yyyy-MM-dd}-WARN-%i.log">  

and you set these variables in your apps.properties:-

CustomapplicationName=Common-logging-Util
CustomapPath=E:/backup/test/log

or if you want to make it more dynamic, you can pass these value from VM argument as -DCustomapPath=E:/backup/test/log -DCustomapplicationName=Common-logging-Util

and in Standalone server as -M-DCustomapplicationName=Common-logging-Util -M-DCustomapPath=E:/backup/test/log

So, now when the application loads you will find the log files generated at the location you mentioned.
But once it's loaded you cannot change the log file path from there as it has already loaded the file location.

查看更多
登录 后发表回答