使用Logback

时间:2016-12-01 15:37:04

标签: java spring-boot wildfly logback

我的Spring启动应用程序在logback.xml配置了Logback。

此应用已部署为*.war至WildFly 8.2.1(独立模式),并已排除WildFly的日志记录。

在部署期间,WildFly会将所有消息记录到控制台,直到配置了我的应用程序的回溯。最后一条消息类似于" ch.qos.logback.classic.joran.JoranConfigurator@5ab89105 - 将当前配置注册为安全回退点" 。 在它之后,我的应用程序继续登录到文件,但来自WildFly的所有消息都消失了(例如" WildFly 8.2.0.Final" Tweek"在37191ms开始 - 开始2666个服务中的2666个( 221种服务是懒惰的,被动的或按需的)" )。

logback.xml:

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">
<contextName>prog</contextName>
<jmxConfigurator />

<include resource="com/app/logback/include.xml" />

<property name="destination" value="${JBOSS_HOME:-./temp}/standalone/log" />
<property name="windowSize" value="21" />
<property name="maxFileSize" value="10000KB" />
<property name="pattern" value="R ${commonPattern}" />

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <layout class="ch.qos.logback.classic.PatternLayout">
        <Pattern>%d{HH:mm:ss.SSS} %-5level %logger{16} - %msg%n</Pattern>
    </layout>
</appender>

<appender name="FILE_APP" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${destination}/prog-app.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
        <fileNamePattern>${destination}/prog-app.log.%i</fileNamePattern>
        <minIndex>1</minIndex>
        <maxIndex>${windowSize}</maxIndex>
    </rollingPolicy>
    <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
        <maxFileSize>${maxFileSize}</maxFileSize>
    </triggeringPolicy>
    <encoder>
        <charset>UTF-8</charset>
        <pattern>${pattern}</pattern>
    </encoder>
</appender>

<appender name="FILE_OTHER" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${destination}/prog-other.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
        <fileNamePattern>${destination}/prog-other.log.%i</fileNamePattern>
        <minIndex>1</minIndex>
        <maxIndex>${windowSize}</maxIndex>
    </rollingPolicy>
    <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
        <maxFileSize>${maxFileSize}</maxFileSize>
    </triggeringPolicy>
    <encoder>
        <charset>UTF-8</charset>
        <pattern>${pattern}</pattern>
    </encoder>
</appender>

<appender name="FILE_RESTS" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${destination}/prog-rests.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
        <fileNamePattern>${destination}/prog-rests.log.%i</fileNamePattern>
        <minIndex>1</minIndex>
        <maxIndex>${windowSize}</maxIndex>
    </rollingPolicy>
    <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
        <maxFileSize>${maxFileSize}</maxFileSize>
    </triggeringPolicy>
    <encoder>
        <charset>UTF-8</charset>
        <pattern>${pattern}</pattern>
    </encoder>
</appender>

<logger name="com.app.prog" level="WARN" additivity="false">
    <appender-ref ref="FILE_APP" />
</logger>

<logger name="com.app.prog.config" level="ERROR" additivity="false">
    <appender-ref ref="FILE_RESTS" />
</logger>

<logger name="com.app.prog.processing" level="ERROR" additivity="false">
    <appender-ref ref="FILE_APP" />
</logger>

<logger name="org.springframework.security" level="WARN" additivity="false">
    <appender-ref ref="FILE_OTHER" />
</logger>

<root level="WARN">
    <appender-ref ref="FILE_OTHER" />
</root>
</configuration>

include.xml:

<included>
    <conversionRule conversionWord="pid" converterClass="com.app.logback.converters.ProcessIdConverter" />
    <conversionRule conversionWord="tid" converterClass="com.app.logback.converters.ThreadIdConverter" />
    <conversionRule conversionWord="memory" converterClass="com.app.logback.converters.MemoryConverter" />

    <property name="commonPattern" value="00000 %.-1level %d{yyyy-MM-dd'T'HH:mm:ss.SSS} P%replace(%6pid){' ', '0'} T%replace(%6tid){' ', '0'} M%replace(%10memory){' ', '0'} -- %msg [%logger{0}:%line]%n" />
</included>

的JBoss部署-structure.xml:

<jboss-deployment-structure>
    <deployment>
        <exclude-subsystems>
            <subsystem name="logging" />
        </exclude-subsystems>
    </deployment>
</jboss-deployment-structure>

logback output (使用debug =&#34; false&#34;属性打印也是出乎意料的):

14:04:57,897 INFO  [stdout] (MSC service thread 1-9) 14:04:57,747 |-INFO in ch.qos.logback.classic.LoggerContext[prog] - Could NOT find resource [logback.groovy]
14:04:57,902 INFO  [stdout] (MSC service thread 1-9) 14:04:57,748 |-INFO in ch.qos.logback.classic.LoggerContext[prog] - Could NOT find resource [logback-test.xml]
14:04:57,909 INFO  [stdout] (MSC service thread 1-9) 14:04:57,748 |-INFO in ch.qos.logback.classic.LoggerContext[prog] - Found resource [logback.xml] at [vfs:/C:/inst/wildfly-8.2.1.Final/bin/content/prog-0.1.0.war/WEB-INF/classes/logback.xml]
14:04:57,932 INFO  [stdout] (MSC service thread 1-9) 14:04:57,759 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@4883a060 - URL [vfs:/C:/inst/wildfly-8.2.1.Final/bin/content/prog-0.1.0.war/WEB-INF/classes/logback.xml] is not of type file
14:04:57,961 INFO  [stdout] (MSC service thread 1-9) 14:04:57,838 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
14:04:57,979 INFO  [stdout] (MSC service thread 1-9) 14:04:57,839 |-INFO in ch.qos.logback.classic.joran.action.ContextNameAction - Setting logger context name as [prog]
14:04:57,986 INFO  [stdout] (MSC service thread 1-9) 14:04:57,839 |-INFO in ch.qos.logback.classic.joran.action.JMXConfiguratorAction - begin
14:04:58,002 INFO  [stdout] (MSC service thread 1-9) 14:04:57,842 |-INFO in ch.qos.logback.core.joran.util.ConfigurationWatchListUtil@6183db43 - Adding [vfs:/C:/inst/wildfly-8.2.1.Final/bin/content/prog-0.1.0.war/WEB-INF/lib/logging-0.0.1-SNAPSHOT.jar/com/app/logback/includedPattern.xml] to configuration watch list.
14:04:58,016 INFO  [stdout] (MSC service thread 1-9) 14:04:57,842 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@4883a060 - URL [vfs:/C:/inst/wildfly-8.2.1.Final/bin/content/prog-0.1.0.war/WEB-INF/lib/logging-0.0.1-SNAPSHOT.jar/com/app/logback/includedPattern.xml] is not of type file
14:04:58,047 INFO  [stdout] (MSC service thread 1-9) 14:04:57,844 |-INFO in ch.qos.logback.core.joran.action.ConversionRuleAction - registering conversion word pid with class [com.app.logback.converters.ProcessIdConverter]
14:04:58,073 INFO  [stdout] (MSC service thread 1-9) 14:04:57,844 |-INFO in ch.qos.logback.core.joran.action.ConversionRuleAction - registering conversion word tid with class [com.app.logback.converters.ThreadIdConverter]
14:04:58,092 INFO  [stdout] (MSC service thread 1-9) 14:04:57,844 |-INFO in ch.qos.logback.core.joran.action.ConversionRuleAction - registering conversion word memory with class [com.app.logback.converters.MemoryConverter]
14:04:58,101 INFO  [stdout] (MSC service thread 1-9) 14:04:57,848 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
14:04:58,109 INFO  [stdout] (MSC service thread 1-9) 14:04:57,850 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
14:04:58,129 INFO  [stdout] (MSC service thread 1-9) 14:04:57,873 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - This appender no longer admits a layout as a sub-component, set an encoder instead.
14:04:58,175 INFO  [stdout] (MSC service thread 1-9) 14:04:57,873 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - To ensure compatibility, wrapping your layout in LayoutWrappingEncoder.
14:04:58,182 INFO  [stdout] (MSC service thread 1-9) 14:04:57,873 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - See also http://logback.qos.ch/codes.html#layoutInsteadOfEncoder for details
14:04:58,190 INFO  [stdout] (MSC service thread 1-9) 14:04:57,873 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
14:04:58,209 INFO  [stdout] (MSC service thread 1-9) 14:04:57,875 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FILE_APP]
14:04:58,215 INFO  [stdout] (MSC service thread 1-9) 14:04:57,880 |-INFO in ch.qos.logback.core.rolling.FixedWindowRollingPolicy@1594e85 - No compression will be used
14:04:58,235 INFO  [stdout] (MSC service thread 1-9) 14:04:57,884 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
14:04:58,244 INFO  [stdout] (MSC service thread 1-9) 14:04:57,887 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE_APP] - Active log file name: C:\inst\wildfly-8.2.1.Final/standalone/log/prog-app.log
14:04:58,265 INFO  [stdout] (MSC service thread 1-9) 14:04:57,887 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE_APP] - File property is set to [C:\inst\wildfly-8.2.1.Final/standalone/log/prog-app.log]
14:04:58,273 INFO  [stdout] (MSC service thread 1-9) 14:04:57,888 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
14:04:58,295 INFO  [stdout] (MSC service thread 1-9) 14:04:57,888 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FILE_OTHER]
14:04:58,301 INFO  [stdout] (MSC service thread 1-9) 14:04:57,889 |-INFO in ch.qos.logback.core.rolling.FixedWindowRollingPolicy@70cb31ef - No compression will be used
14:04:58,324 INFO  [stdout] (MSC service thread 1-9) 14:04:57,889 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
14:04:58,342 INFO  [stdout] (MSC service thread 1-9) 14:04:57,890 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE_OTHER] - Active log file name: C:\inst\wildfly-8.2.1.Final/standalone/log/prog-other.log
14:04:58,353 INFO  [stdout] (MSC service thread 1-9) 14:04:57,890 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE_OTHER] - File property is set to [C:\inst\wildfly-8.2.1.Final/standalone/log/prog-other.log]
14:04:58,375 INFO  [stdout] (MSC service thread 1-9) 14:04:57,890 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
14:04:58,384 INFO  [stdout] (MSC service thread 1-9) 14:04:57,890 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FILE_RESTS]
14:04:58,391 INFO  [stdout] (MSC service thread 1-9) 14:04:57,891 |-INFO in ch.qos.logback.core.rolling.FixedWindowRollingPolicy@259e0f36 - No compression will be used
14:04:58,411 INFO  [stdout] (MSC service thread 1-9) 14:04:57,891 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
14:04:58,427 INFO  [stdout] (MSC service thread 1-9) 14:04:57,892 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE_RESTS] - Active log file name: C:\inst\wildfly-8.2.1.Final/standalone/log/prog-rests.log
14:04:58,440 INFO  [stdout] (MSC service thread 1-9) 14:04:57,892 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE_RESTS] - File property is set to [C:\inst\wildfly-8.2.1.Final/standalone/log/prog-rests.log]
14:04:58,459 INFO  [stdout] (MSC service thread 1-9) 14:04:57,893 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.app.prog] to WARN
14:04:58,475 INFO  [stdout] (MSC service thread 1-9) 14:04:57,893 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [com.app.prog] to false
14:04:58,488 INFO  [stdout] (MSC service thread 1-9) 14:04:57,893 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FILE_APP] to Logger[com.app.prog]
14:04:58,506 INFO  [stdout] (MSC service thread 1-9) 14:04:57,894 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.app.prog.config] to ERROR
14:04:58,523 INFO  [stdout] (MSC service thread 1-9) 14:04:57,894 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [com.app.prog.config] to false
14:04:58,540 INFO  [stdout] (MSC service thread 1-9) 14:04:57,894 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FILE_RESTS] to Logger[com.app.prog.config]
14:04:58,555 INFO  [stdout] (MSC service thread 1-9) 14:04:57,894 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.app.prog.processing] to ERROR
14:04:58,572 INFO  [stdout] (MSC service thread 1-9) 14:04:57,894 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [com.app.prog.processing] to false
14:04:58,588 INFO  [stdout] (MSC service thread 1-9) 14:04:57,894 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FILE_APP] to Logger[com.app.prog.processing]
14:04:58,607 INFO  [stdout] (MSC service thread 1-9) 14:04:57,894 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework.security] to WARN
14:04:58,622 INFO  [stdout] (MSC service thread 1-9) 14:04:57,894 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting additivity of logger [org.springframework.security] to false
14:04:58,663 INFO  [stdout] (MSC service thread 1-9) 14:04:57,894 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FILE_OTHER] to Logger[org.springframework.security]
14:04:58,673 INFO  [stdout] (MSC service thread 1-9) 14:04:57,894 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to WARN
14:04:58,688 INFO  [stdout] (MSC service thread 1-9) 14:04:57,894 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FILE_OTHER] to Logger[ROOT]
14:04:58,703 INFO  [stdout] (MSC service thread 1-9) 14:04:57,894 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
14:04:58,709 INFO  [stdout] (MSC service thread 1-9) 14:04:57,894 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@5ab89105 - Registering current configuration as safe fallback point

我的logback.xml配置可能有些东西,但我无法弄清楚究竟是什么(我不是WildFly和Logback配置中的大师)。

感谢任何帮助。 感谢。

编辑: 当我从logback.xml

中删除<root>部分时,它变得有效

0 个答案:

没有答案