加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

logback.xml

发布时间:2020-12-16 00:02:56 所属栏目:百科 来源:网络整理
导读:Let us begin by discussing the initialization steps that logback follows to try to configure itself: Logback tries to find a file called logback-test.xml in the classpath. If no such file is found,logback tries to find a file called logbac

Let us begin by discussing the initialization steps that logback follows to try to configure itself:

  1. Logback tries to find a file calledlogback-test.xmlin the classpath.

  2. If no such file is found,logback tries to find a file calledlogback.groovyin the classpath.

  3. If no such file is found,it checks for the filelogback.xmlin the classpath..

  4. If no such file is found,service-provider loading facility(introduced in JDK 1.6) is used to resolve the implementation ofcom.qos.logback.classic.spi.Configuratorinterface by looking up the fileMETA-INFservicesch.qos.logback.classic.spi.Configuratorin the class path. Its contents should specify the fully qualified class name of the desiredConfiguratorimplementation.

  5. If none of the above succeeds,logback configures itself automatically using theBasicConfiguratorwhich will cause logging output to be directed to the console.

Settingdebug="true"within the <configuration> element will output status information,assuming that:

  1. the configuration file is found
  2. the configuration file is well-formed XML.

If any of these two conditions is not fulfilled,Joran cannot interpret thedebugattribute since the configuration file cannot be read. If the configuration file is found but is malformed,then logback will detect the error condition and automatically print its internal status on the console. However,if the configuration file cannot be found,logback will not automatically print its status data,since this is not necessarily an error condition. Programmatically invokingStatusPrinter.print()as shown in theMyApp2application above ensures that status information is printed in every case.

the logback.xml configuration:

<?xml version="1.0" encoding="UTF-8"?>

<configuration debug="true">

<property resource="application.properties"/>

<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">

<file>/logdocument.log</file>

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">

<!-- daily rollover -->

<fileNamePattern>/logdocument.log.%d{yyyy-MM-dd}.log</fileNamePattern>

<!-- keep 30 days' worth of history -->

<maxHistory>30</maxHistory>

</rollingPolicy>

<encoder>

<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>

</encoder>

</appender>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">

<logger name="org.springframework" level="INFO"/>

<logger name="org.hibernate" level="INFO"/>

<root level="info">

<appender-ref ref="FILE" />

<appender-ref ref="STDOUT" />

</root>

</configuration>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读