javalogginglogbackslf4jlogback-classic

Logback Logger has no Appenders


I have a Vaadin webapplikation using slf4 and logback. In which I am using a Console and a DBAppender. Everything works fine if I use the logging in a Testcase:

    @Test
    public void test() {
        Logger logger=  LoggerFactory.getLogger("TEST");
        logger.info("Teste");
}

But if im using a Logger in the Applikation nothing happens. No debug output from Logback and also no output from my logger calls.

Gradle:

compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
compile group: 'ch.qos.logback', name: 'logback-core', version: '1.2.3'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'

logback.xml:

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug ="true">
    <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
        <!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n
            </pattern>
        </encoder>
    </appender>
    <appender name="db" class="ch.qos.logback.classic.db.DBAppender">
        <connectionSource
                class="ch.qos.logback.core.db.DriverManagerConnectionSource">
            <driverClass>org.postgresql.Driver</driverClass>
            <url>jdbc:postgresql://localhost:5432/test</url>
            <user>postgres</user>
            <password></password> <!-- no password -->
        </connectionSource>
    </appender>

    <!-- the level of the root level is set to DEBUG by default. -->
    <root level="INFO">
        <appender-ref ref="stdout" />
        <appender-ref ref="db" />
    </root>
</configuration>

EDIT: When I remove the logback-dependencies and add

compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25'

everything works but sadly this is not an option because I need the dpAppender

EDIT2 By debugging i found out that no appenders are added to the logger at all. In the following code from ch.qos.logback.classic:

public void callAppenders(ILoggingEvent event) {
    int writes = 0;
    for (Logger l = this; l != null; l = l.parent) {
        writes += l.appendLoopOnAppenders(event);
        if (!l.additive) {
            break;
        }
    }
    // No appenders in hierarchy
    if (writes == 0) {
        loggerContext.noAppenderDefinedWarning(this);
    }
}

private int appendLoopOnAppenders(ILoggingEvent event) {
    if (aai != null) {
        return aai.appendLoopOnAppenders(event);
    } else {
        return 0;
    }
}

aai's size is 0


Solution

  • The lack of Appenders was caused by the gradle vaadin plug-in I was using to execute the application. It was solved when I replaced the vaadin plug-in with gretty.