[JBoss] Quarkus logger does not use the logger name

Discussão em 'StackOverflow' iniciado por Stack, Outubro 12, 2024.

  1. Stack

    Stack Membro Participativo

    I've created a simple hello world applicaiton to test logging with quarkus. I've noticed that the @LoggerName does not seem to work as inteded

    I've created a class

    package org.acme.customlogger;

    import org.jboss.logging.Logger;

    import io.quarkus.arc.log.LoggerName;
    import jakarta.enterprise.context.ApplicationScoped;
    import jakarta.inject.Inject;

    @ApplicationScoped
    public class MyCustomLogger {

    @LoggerName("foo.bar.logger")
    Logger logger;

    @Inject
    Logger log;


    public void log() {
    logger.info("loggername");
    log.info("regular inject");
    }
    }


    and a test

    package org.acme;

    import org.acme.customlogger.MyCustomLogger;
    import org.junit.jupiter.api.Test;

    import io.quarkus.test.junit.QuarkusTest;
    import jakarta.inject.Inject;


    @QuarkusTest
    public class CustomLoggerTest {

    @Inject
    MyCustomLogger myCustomLogger;

    @Test
    public void quarkus_log_test() {
    myCustomLogger.log();

    }

    }


    in the test i'm seeing the output

    Oct 12, 2024 10:48:33 AM org.acme.customlogger.MyCustomLogger log
    INFO: loggername
    Oct 12, 2024 10:48:33 AM org.acme.customlogger.MyCustomLogger log
    INFO: regular inject


    which is not expected, i would assume foo.bar.logger would be used instead of org.acme.customlogger.MyCustomLogger for the line INFO: loggername

    Here is my pom file so you can see versions

    <?xml version="1.0" encoding="UTF-8"?>
    <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>org.acme</groupId>
    <artifactId>code-with-quarkus</artifactId>
    <version>1.0.0-SNAPSHOT</version>

    <properties>
    <compiler-plugin.version>3.13.0</compiler-plugin.version>
    <maven.compiler.release>21</maven.compiler.release>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
    <quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
    <quarkus.platform.version>3.15.1</quarkus.platform.version>
    <skipITs>true</skipITs>
    <surefire-plugin.version>3.3.1</surefire-plugin.version>
    </properties>

    <dependencyManagement>
    <dependencies>
    <dependency>
    <groupId>${quarkus.platform.group-id}</groupId>
    <artifactId>${quarkus.platform.artifact-id}</artifactId>
    <version>${quarkus.platform.version}</version>
    <type>pom</type>
    <scope>import</scope>
    </dependency>
    </dependencies>
    </dependencyManagement>

    <dependencies>
    <dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-rest</artifactId>
    </dependency>
    <dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-rest-jackson</artifactId>
    </dependency>
    <dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-arc</artifactId>
    </dependency>
    <dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-junit5</artifactId>
    <scope>test</scope>
    </dependency>
    <dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>rest-assured</artifactId>
    <scope>test</scope>
    </dependency>
    </dependencies>

    <build>
    <plugins>
    <plugin>
    <groupId>${quarkus.platform.group-id}</groupId>
    <artifactId>quarkus-maven-plugin</artifactId>
    <version>${quarkus.platform.version}</version>
    <extensions>true</extensions>
    <executions>
    <execution>
    <goals>
    <goal>build</goal>
    <goal>generate-code</goal>
    <goal>generate-code-tests</goal>
    <goal>native-image-agent</goal>
    </goals>
    </execution>
    </executions>
    </plugin>
    <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>${compiler-plugin.version}</version>
    <configuration>
    <parameters>true</parameters>
    </configuration>
    </plugin>
    <plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>${surefire-plugin.version}</version>
    <configuration>
    <systemPropertyVariables>
    <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
    <maven.home>${maven.home}</maven.home>
    </systemPropertyVariables>
    </configuration>
    </plugin>
    <plugin>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>${surefire-plugin.version}</version>
    <executions>
    <execution>
    <goals>
    <goal>integration-test</goal>
    <goal>verify</goal>
    </goals>
    </execution>
    </executions>
    <configuration>
    <systemPropertyVariables>
    <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
    <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
    <maven.home>${maven.home}</maven.home>
    </systemPropertyVariables>
    </configuration>
    </plugin>
    </plugins>
    </build>

    <profiles>
    <profile>
    <id>native</id>
    <activation>
    <property>
    <name>native</name>
    </property>
    </activation>
    <properties>
    <skipITs>false</skipITs>
    <quarkus.native.enabled>true</quarkus.native.enabled>
    </properties>
    </profile>
    </profiles>
    </project>


    I've tried setting the category in application.properties

    quarkus.log.category."foo.bar.logger".level=DEBUG


    but this should not be needed according too

    https://quarkus.io/guides/logging

    Continue reading...

Compartilhe esta Página