欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用log4j2關(guān)閉debug日志

 更新時(shí)間:2021年12月24日 11:48:43   作者:鳳鳴86  
這篇文章主要介紹了使用log4j2關(guān)閉debug日志方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

log4j2關(guān)閉debug日志

最近項(xiàng)目引進(jìn)入一個(gè)jar包,啟動(dòng)之之后debug日志就停不下來了,為了關(guān)閉這個(gè)日志花了半個(gè)下午。總結(jié)以下處理方式,以供大家參考:

1.如果引入了logback的jar包

排除引用(我的項(xiàng)目里沒有引用)

<exclusions>
 <exclusion>
  <groupId>ch.qos.logback</groupId>
  <artifactId>logback-classic</artifactId>
 </exclusion>
 <exclusion>
  <groupId>ch.qos.logback</groupId>
  <artifactId>logback-core</artifactId>
 </exclusion>
</exclusions>

2.調(diào)整log4j2的日志打印級別

log4j2.xml(對于我的項(xiàng)目沒有起作用)

<configuration status="info" monitorInterval="600" >

3.指定加載文件web.xml

添加指定日志文件 (我的項(xiàng)目無效)

  <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>WEB-INF/classes/log4j2.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
  </listener>

4.添加log4j.properties

對于我的項(xiàng)目有效

log4j.rootLogger=info,stdout

備注:因?yàn)槲业捻?xiàng)目里由于第三方j(luò)ar包引入了slf4j-log4j12和log4j2沖突,所以exclude掉slf4j-log4j12 jar包就是可以的

Log4J和slf4j的debug日志問題

很多人知道

在使用slf4j的過程中通常會(huì)引入兩個(gè)jar包

大概如下:

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.21</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>1.7.21</version>
</dependency>

當(dāng)使用最終的日志實(shí)現(xiàn)

如Log4j時(shí),又會(huì)引入log4j相關(guān)的jar包,如下:

<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.7.21</version>
</dependency>

這樣就可以在Java應(yīng)用程序(Java Web服務(wù)和Java程序)中,輸出由slf4j編寫的日志。

但在使用過程中發(fā)現(xiàn),在執(zhí)行測試用例(加載Spring或未加載Spring)的時(shí)候,不管怎么配置log4j.properties文件,都會(huì)出現(xiàn)部分debug日志輸出不了的情況,具體就是自己寫的那部分的debug日志不會(huì)輸出,而如Spring或MyBatis等框架的debug日志就可以輸出。

后面根據(jù)slf4j的警告日志,說是有多個(gè)日志實(shí)現(xiàn),從而不確定具體選哪一個(gè)具體日志實(shí)現(xiàn)。經(jīng)過進(jìn)一步的調(diào)試,刪除slf4j-simple的依賴后,所有的debug日志都可以如期的輸出。

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論