Dynamic log file path in mule

℡╲_俬逩灬. 提交于 2019-12-11 05:10:35

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/40814536/dynamic-log-file-path-in-mule

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