how to set log4j2 and spring boo2 deploy on wildfly 26

1,791 views
Skip to first unread message

陳朝友

unread,
Feb 24, 2022, 10:34:57 AM2/24/22
to WildFly
Hi all,

I can't run my spring boot war when using log4j2 deploy to wildfly26

the error message is: java.lang.RuntimeException: org.apache.logging.log4j.LoggingException: log4j-slf4j-impl cannot be present with log4j-to-slf4j

pom.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.6.3</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>

<dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      <exclusions>
        <exclusion>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-thymeleaf</artifactId>
      <exclusions>
        <exclusion>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-core</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-api</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-slf4j-impl</artifactId>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>jul-to-slf4j</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
      <scope>provided</scope>
    </dependency>
  </dependencies>

jboss-deplyment-structure.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
        <!-- Exclusions allow you to prevent the server from automatically adding some dependencies -->
        <exclusions>
<!--            <module name="org.slf4j" />-->
<!--            <module name="org.slf4j.impl" />-->
            <module name="org.apache.log4j" />
<!--            <module name="org.apache.logging.log4j" />-->
<!--            <module name="org.apache.commons.logging"/>-->
        </exclusions>
        <exclude-subsystems>
            <subsystem name="logging" />
        </exclude-subsystems>
    </deployment>
</jboss-deployment-structure>


log4j2-spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>

<configuration status="INFO" packages="com.chttl.svs">

  <Appenders>
    <Console name="CONSOLE">
      <PatternLayout pattern="%date{HH:mm:ss.sss} %-5level [%thread] %logger{0}: %msg%n" />
    </Console>

    <RollingFile name="FILE" fileName="/svs/log/svs.log" filePattern="/svs/log/logFile.%d{yyyy-MM-dd}">
      <PatternLayout pattern="%date{yyyy-MM-dd HH:mm:ss.SSS} %level [%thread][%file:%line] - %msg%n" />
      <Policies>
        <TimeBasedTriggeringPolicy />
      </Policies>
    </RollingFile>
  </Appenders>

  <Loggers>
    <Root level="info">
      <AppenderRef ref="CONSOLE" />
      <AppenderRef ref="FILE" />
    </Root>

    <Logger name="com.chttl.svs" level="debug" />
  </Loggers>
</configuration>



James Perkins

unread,
Feb 24, 2022, 10:59:10 AM2/24/22
to WildFly
You'd need to look at your dependency tree to see where log4j-to-slf4j is coming from. WildFly does not provide that so it must be coming from some dependency in your POM.

This is not quite correct. If you want to use log4j2 and slf4j you need to exclude the modules org.apache.logging.log4j and org.slf4j. The org.apache.log4j module is log4j 1.

陳朝友

unread,
Feb 25, 2022, 3:25:45 AM2/25/22
to WildFly
Hi jper,

thanks, you save my day!!

Finally,  I've found log4j-to-slf4j.jar in my project libs, not any dependency in the pom and update jboss-deployment-structure.xml follow your opinion.

Chao

jper...@redhat.com 在 2022年2月24日 星期四下午11:59:10 [UTC+8] 的信中寫道:
Reply all
Reply to author
Forward
0 new messages