在运行时通过外部属性文件更改日志记录中的日志级别 [英] Change log level in logback at run time via external property file

查看:119
本文介绍了在运行时通过外部属性文件更改日志记录中的日志级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在不重新启动服务器的情况下更改日志级别.我使用weblogic服务器.为此,我想通过外部文件(LOGBackIncludedFile.xml)传递日志级别,并在logback <include file>中提供此文件路径. 我无法对路径进行硬编码,因为DevUATProduction中的路径不同.我想将此文件包含在Weblogic 12C服务器内部的某个位置.因此,我无需更改ear文件即可更改日志级别.

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>

下面是LOGBackIncludedFile.xml

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

使用现有的xml时,出现此错误.

when I use this existing xml I get this error.

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

我的问题是如何在logback.xml中动态设置外部文件路径.路径应为特定的weblogic instance.当我将外部文件放入实例中时.

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.

例如:/usrxx/appxx/oracle/product/XXX/domains/xxxDomain/servers/myInstance/

推荐答案

按如下所示设置文件路径.这是针对weblogic 12C的.

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

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

这篇关于在运行时通过外部属性文件更改日志记录中的日志级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆