简体   繁体   中英

Dynamic log file path in mule

我试图动态更改mule中的日志文件路径我已经在表达式组件中设置了系统属性但是因为log4j2.XML在编译时解码了值本身它没有被反映我甚至在log4j.XML中设置了监视器间隔但是它是不是如何实现动态文件路径?

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.

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.

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