Skip to content

Some logs are dismissed during context creation #7772

Open
@romainmoreau

Description

@romainmoreau

The default logging system is used (Logback).

For instance, the warning logged here is dismissed.
This behavior appears because at the time the warning is logged, the Logback context contains a filter that denies everything.

This issue is similar to #7758 but it's with Logback.

Here's a quick and dirty demo:

package demo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class DemoApplication {
    private static final Logger LOGGER = LoggerFactory.getLogger(DemoApplication.class);

    @Value("${demo.value:empty}")
    private String demoValue;

    @Bean
    public CommandLineRunner commandLineRunner() {
        return new CommandLineRunner() {
            @Override
            public void run(String... args) throws Exception {
                LOGGER.warn("value = {}", demoValue);
            }
        };
    }

    public static void main(String[] args) throws Exception {
        // Valid JSON:
        // System.setProperty("SPRING_APPLICATION_JSON", "{\"demo\":{\"value\":\"demo\"}}");
        // Invalid JSON:
        System.setProperty("SPRING_APPLICATION_JSON", "{");
        SpringApplication.run(DemoApplication.class, args);
    }
}
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>demo</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.3.RELEASE</version>
    </parent>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
    </dependencies>
</project>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions