Change log level in logback at run time via external property file

家住魔仙堡 提交于 2019-12-11 12:53:41

问题


I want to change the log level without restarting the server. I use weblogic server. For this I thought to pass the log level from a external file (LOGBackIncludedFile.xml) and give this file path in the logback <include file>. I cannot hard code the path, as the path is different in Dev, UAT, Production. I want to include this file in a location inside Weblogic 12C server. So I can change log level without touching ear file.

<configuration  scan="true"  scanPeriod="30 seconds">

   <include file="../../LOGBackIncludedFile.xml" />
   <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender" >
       <encoder>
         <pattern>%date %-5level [%logger] > %msg%n</pattern>
       </encoder>
  </appender>

  <root level="${root.level:-DEBUG}">          
    <appender-ref ref="STDOUT" />
  </root>  
</configuration>

Below is the LOGBackIncludedFile.xml

<included>
  <property value="INFO" name="root.level"/>
</included>

when I use this existing xml I get this error.

 java.io.FileNotFoundException: /usrXX/appXX/oracle/product/XXX/domains/XXXDomain/../../LOGBackIncludedFile.xml 

My question is how can I set external file path dynamically in the logback.xml. The path should be to the specific weblogic instance. As I put the external file into my instance.

eg : /usrxx/appxx/oracle/product/XXX/domains/xxxDomain/servers/myInstance/


回答1:


Set the file path as below. This is for weblogic 12C.

 <include optional="true" file="${DOMAIN_HOME}/servers/${SERVER_NAME}/LOGBackIncludedFile.xml" />


来源:https://stackoverflow.com/questions/30976870/change-log-level-in-logback-at-run-time-via-external-property-file

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