添加 spring-boot-starter-security 后,Spring boot loggs loggs 总是到 System.err

问题描述 投票:0回答:0

添加 spring-boot-starter-security 日志记录后,所有日志都重定向到 system.err 在我的 build.grade 中,我不得不排除 logback,因为从 IntelliJ 内部启动的应用程序总是失败。

我排除了如下的logback

configurations {
    all {
        exclude group: 'ch.qos.logback', module: 'logback-classic'
    }
}

并添加

    implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.20.0'

我的 build.gradle 的其余部分如下所示:

    // Spring Boot
    implementation group: "org.springframework.boot", name: "spring-boot-starter-actuator"
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter'
    implementation group: "org.springframework.boot", name: "spring-boot-starter-web"
    implementation group: "org.springframework.boot", name: "spring-boot-configuration-processor"


    // security
    implementation group: "org.springframework.boot", name: "spring-boot-starter-security"
    implementation group: "org.springframework.boot", name: "spring-boot-starter-oauth2-client"
    implementation group: "org.springframework.boot", name: "spring-boot-starter-oauth2-resource-server"
    implementation group: "org.springframework.security", name: "spring-security-oauth2-jose"


    // Swagger/OpenAPI CodeGen
    implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.14'
    implementation group: 'org.springdoc', name: 'springdoc-openapi-common', version: '1.6.14'
    implementation group: "org.openapitools", name: "jackson-databind-nullable", version: "0.2.4"

    implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.20.0'

    compileOnly group: 'org.openapitools', name: 'openapi-generator-maven-plugin', version: '6.2.1'
    compileOnly group: "org.projectlombok", name: "lombok"
    annotationProcessor group: "org.projectlombok", name: "lombok"

    annotationProcessor group: "org.springframework.boot", name: "spring-boot-configuration-processor"

    // Utils
    implementation 'commons-io:commons-io:2.8.0'

    // Test
    testImplementation group: "org.springframework.boot", name: "spring-boot-starter-test"
    testImplementation group: "org.springframework.security", name: "spring-security-test"
    testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.9.1'
    testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: '4.10.0'

}

我预计在添加 spring-boot-starter-security 之前,log begaviour 会是这样。 但似乎仍然使用 java.logging 总是记录到 System.err

spring-boot logging spring-security log4j slf4j
© www.soinside.com 2019 - 2024. All rights reserved.