2014-11-08 54 views
3

當的logback與Wildfly8獨立的所有日誌消息似乎被Wildfly記錄儀捕獲:Wildfly8/JBoss的包裝的logback日誌(雙人間前綴)

21:13:18,808 INFO [stdout] (default task-4) 21:13:18.806 [default task-4] ERROR some.package.MyClass - Some message 
21:13:18,810 INFO [stdout] (default task-4) 21:13:18.809 [default task-4] WARN some.package.MyClass - Some message 
21:13:18,810 INFO [stdout] (default task-4) 21:13:18.810 [default task-4] INFO some.package.MyClass - Some message 
21:13:18,810 INFO [stdout] (default task-4) 21:13:18.810 [default task-4] DEBUG some.package.MyClass - Some message 
21:13:18,811 INFO [stdout] (default task-4) 21:13:18.811 [default task-4] TRACE some.package.MyClass - Some message 

我想省略由Wildfly添加的第一部分,以使這些信息將看起來像這樣:

21:13:18.806 [default task-4] ERROR some.package.MyClass - Some message 
21:13:18.809 [default task-4] WARN some.package.MyClass - Some message 
21:13:18.810 [default task-4] INFO some.package.MyClass - Some message 
21:13:18.810 [default task-4] DEBUG some.package.MyClass - Some message 
21:13:18.811 [default task-4] TRACE some.package.MyClass - Some message 

有誰知道如何做到這一點?

WEB_INF /班/ logback.xml:

<configuration> 
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> 
     <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> 
      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> 
     </encoder> 
    </appender> 
    <logger name="org.hibernate" level="ERROR" /> 
    <logger name="org.jboss.logging" level="INFO" /> 
    <root level="ALL"> 
     <appender-ref ref="STDOUT" /> 
    </root> 
</configuration> 

WEB-INF/jboss的部署,structure.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2"> 
    <deployment> 
     <exclude-subsystems> 
      <subsystem name="logging" /> 
     </exclude-subsystems> 
     <exclusions> 
      <module name="org.apache.commons.logging" /> 
      <module name="org.apache.log4j" /> 
      <module name="org.jboss.logging" /> 
      <module name="org.jboss.logging.jul-to-slf4j-stub" /> 
      <module name="org.jboss.logmanager" /> 
      <module name="org.jboss.logmanager.log4j" /> 
      <module name="org.slf4j" /> 
      <module name="org.slf4j.impl" /> 
     </exclusions> 
    </deployment> 
</jboss-deployment-structure> 

從POM相關信息:

<packaging>war</packaging> 
<!-- JAVA EE --> 
<dependency> 
    <groupId>javax</groupId> 
    <artifactId>javaee-api</artifactId> 
    <version>7.0</version> 
    <scope>provided</scope> 
</dependency> 
<!-- LOGGING --> 
<dependency> 
    <groupId>ch.qos.logback</groupId> 
    <artifactId>logback-classic</artifactId> 
    <version>1.1.2</version> 
</dependency> 
+0

嘗試答案在這裏: [StackOverflow上wildfly] [1] [1]:http://stackoverflow.com/questions/23079492/slf4j-logback-does-not-log-in-wildfly – 2015-03-30 07:02:34

回答

1

其中一個解決方案是將記錄器類別stdout和特殊handler添加到您的Wild ly/JBoss配置文件(例如standalone.xml):

像這樣:

<console-handler name="APP_CONSOLE"> 
    <formatter> 
     <pattern-formatter pattern="%s%e%n"/> 
    </formatter> 
</console-handler> 
<logger category="stdout" use-parent-handlers="false"> 
    <handlers> 
    <handler name="APP_CONSOLE"/> 
    </handlers> 
</logger> 

不要忘了use-parent-handlers="false",否則會從根記錄繼承處理。