Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wildfly8/jBoss wraps Logback logs (Double prefix)

When Logback with Wildfly8 standalone all log messages seems to be captured by Wildfly logger:

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

I want to omit the first part added by Wildfly so that the messages will look something like this:

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

Does anyone know how to achieve this?

WEB_INF/classes/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-deployment-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>

Relevant info from 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>
like image 362
PalSivertsen Avatar asked Oct 31 '22 14:10

PalSivertsen


1 Answers

One of the solutions is to add a logger category stdout and a special handler to your Wildfly / JBoss configuration file (e.g. standalone.xml):

Like this:

<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>

Do not forget the use-parent-handlers="false", otherwise it would inherit handlers from the root logger.

like image 164
damien Avatar answered Dec 02 '22 16:12

damien