xml Mise en place de logback dans une application JAVA

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了xml Mise en place de logback dans une application JAVA相关的知识,希望对你有一定的参考价值。

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Application {
	private static final Logger logger = LoggerFactory.getLogger(Application.class);

	public static void main(String[] args) {
		logger.trace("msg de trace");
		logger.debug("msg de debogage");
		logger.info("msg d'information");
		logger.warn("msg d'avertissement");
		logger.error("msg d'erreur");
	}
}
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false" scan="true" scanPeriod="30 seconds">
  <property name="LOGS_FOLDER" value="logs" />
  <property name="LOGS_TO_COLLECT_FOLDER" value="logs-to-collect" />

  <property scope="context" name="log.pattern1"       value="%d{dd/MM/yyyy HH:mm:ss.SSS} %-5level [%thread][%class{0}.%method:%line][%logger{0}] : %m%n" />
  <property scope="context" name="log.pattern2"       value="%d{yyyyMMdd'T'HHmmss.SSS} %-5level [%thread][%logger{0}] %m%n" />
  <property scope="context" name="log.pattern3"       value="%d{yyyy/MM/dd HH:mm:ss.SSS,Europe/Paris} %-5level  [%thread] - %logger{36} - %m%n" />
  <property scope="context" name="log.pattern_log"    value="%d{yyyy/MM/dd HH:mm:ss,SSS} [%thread] %-5level %logger{36} - %m %throwable{0}%n" />
  <property scope="context" name="log.pattern_audit"  value="%m %throwable{0}%n" />
  <property scope="context" name="log.pattern_stdout" value="%d{HH:mm:ss.SSS, Europe/Paris} %highlight(%-5level) [%thread][%logger{0}] : %m%n" />
  <property scope="context" name="log.pattern_simple_stdout" value="%m%n" />
  <!--  <statusListener class="ch.qos.logback.core.status.NopStatusListener" />  -->

  <!-- Insert the current time formatted as "yyyyMMdd'T'HHmmss" under
       the key "bySecond" into the logger context. This value will be
       available to all subsequent configuration elements. -->
  <timestamp key="bySecond" datePattern="yyyyMMdd'T'HHmmss"/>


<!--  
      ******** Sur la console
 -->
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <!-- <withJansi>true</withJansi> -->
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
      <level>DEBUG</level>
    </filter>
    <encoder>
      <charset>utf-8</charset>
      <pattern>${log.pattern_stdout}</pattern>
    </encoder>
  </appender>

<!--  
      ******** XML
 -->
  <appender name="xml" class="ch.qos.logback.core.FileAppender">
    <file>${LOGS_FOLDER}/application.xml</file>
    <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
      <layout class="ch.qos.logback.classic.log4j.XMLLayout">
        <locationInfo>true</locationInfo>
      </layout>
    </encoder> 
  </appender> 

<!--  
      ******** FICHIER HTML
 -->
  <appender name="html" class="ch.qos.logback.core.FileAppender">
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
      <level>INFO</level>
    </filter>
    <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
      <layout class="ch.qos.logback.classic.html.HTMLLayout">
        <pattern>%relative%thread%mdc%level%logger%msg</pattern>
      </layout>
    </encoder>
    <file>${LOGS_FOLDER}/application.html</file>
  </appender>


<!--  
      ******** Fichier par date (troubleshooting)
 -->
  <appender name="log-file-history" class="ch.qos.logback.core.FileAppender">
    <file>${LOGS_FOLDER}/application-troubleshooting-${bySecond}.log</file>
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
      <level>DEBUG</level>
    </filter>
    <encoder>
      <charset>UTF-8</charset> 
      <outputPatternAsHeader>false</outputPatternAsHeader>
      <pattern>${log.pattern1}</pattern>
    </encoder>
  </appender>
 
<!--  
      ******** Fichier log pour production
 -->
  <appender name="log-file" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${LOGS_FOLDER}/application.log</file>
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
      <level>INFO</level>
    </filter>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <fileNamePattern>${LOGS_TO_COLLECT_FOLDER}/application.%d{yyyyMMdd}.log</fileNamePattern>
    </rollingPolicy>
    <encoder>
      <charset>UTF-8</charset> 
      <outputPatternAsHeader>true</outputPatternAsHeader>
      <pattern>${log.pattern2}</pattern>
    </encoder>
  </appender>

  <!-- additivity=false : empeche les parents de recevoir le log  -->

  <logger name="fr.manastria" additivity="false">
    <level value="TRACE" />
    <appender-ref ref="STDOUT" />
    <appender-ref ref="log-file" />
    <appender-ref ref="log-file-history" />
    <appender-ref ref="xml" />
    <appender-ref ref="html" />
  </logger>

  <root>
    <level value="INFO" />
    <appender-ref ref="STDOUT" />
  </root>
</configuration>

以上是关于xml Mise en place de logback dans une application JAVA的主要内容,如果未能解决你的问题,请参考以下文章

从 google api 获取 EN、IT、FR、DE、ES 本地化城市名称

text Problema cuando el checkout agregeements no es aceptado y se presiona el boton de place order。

python字符串的增删改查

使用 XSLT 为 XML 到 HTML 转换中的不同 <place> 标记添加超链接

log(A/B) = logA -logB

PHP salto de linea en PFDF(generador de PDFs en PHP)