Search code examples
javaspring-bootloggingjbosswildfly

Wildfly change log level runtime stop working when deploy springboot application


I'm using Wildfly 24.0.1 and have a lot of applications running in the same server-group, normal war applications and changing log level using wildfly console work as expected. When I access the wildfly console => configuration => profiles => logging => categories and change any time and it works. However, when I deploy a SpringBoot application and try to change any application log level it updates de configuration, but keeps logging the last configuration, for example: It was logging INFO level, I deploy springboot application and then change the log level to ERROR. It keeps logging INFO level.

I tried removing all log libs from my springboot application, change jboss-structure-file, even update springboot version, but nothing works.

Following my springboot pom file:

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>group.id</groupId>
    <artifactId>project-name</artifactId>
    <version>1.0.0</version>
    <name>project-name</name>
    <packaging>war</packaging>
    <description></description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <!-- Compatibility Wildfly (OVERRIDE SPRINGBOOT) -->
        <classmate.version>1.4.0</classmate.version>
        <jackson-bom.version>2.9.9.20190807</jackson-bom.version>
    </properties>

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

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-amqp</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.amqp</groupId>
            <artifactId>spring-rabbit-test</artifactId>
            <scope>test</scope>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- OUTRAS DEPENDENCIAS -->
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
        </dependency>

        <dependency>
            <groupId>org.reflections</groupId>
            <artifactId>reflections</artifactId>
            <version>0.10.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <profiles>
                        <profile>dev</profile>
                        <profile>prod</profile>
                    </profiles>
                </configuration>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>
    <profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <spring.profiles.active>dev</spring.profiles.active>
            </properties>
        </profile>
        <profile>
            <id>prod</id>
            <properties>
                <spring.profiles.active>prod</spring.profiles.active>
            </properties>
            <!-- <DEPENDENCIES> required to work with wildfly -->
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-amqp</artifactId>
                    <exclusions>
                        <exclusion>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-starter-logging</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
            </dependencies>

        </profile>
    </profiles>

</project>

jboss-deployment-structure.xml

<?xml version='1.0' encoding='UTF-8'?>
<jboss-deployment-structure
    xmlns="urn:jboss:deployment-structure:1.1">
    <deployment>
    </deployment>
</jboss-deployment-structure>

The project works, starts, even logs correct, but if I try to update log level at runtime it doesn't work.


Solution

  • After 2 days, tested with 2 springboot applications and got it working.

    I didn't need to change the pom file, it was already excluding "spring-boot-starter-logging" lib.

    To get it working just need to add inside "src/main/resources/" the file "logging.properties" as follows:

    # Define default log level to OFF
    .level=OFF
    # deactivate org.springframework package logs
    org.springframework.level=OFF