【问题标题】:Problem with configuring log4j2.properties into spring boot( using gradle)将 log4j2.properties 配置到 Spring Boot 中的问题(使用 gradle)
【发布时间】:2019-10-26 15:14:29
【问题描述】:

我在 scr/main/resources 中添加了一个 log4j2.properties 文件,但它没有受到影响。 log4j2.properties 不应该被自己检测到。如何检查它是否未被检测到??

Log4j2.properties 文件

status = error
name = PropertiesConfig

filters = threshold

filter.threshold.type = ThresholdFilter
filter.threshold.level = debug

appenders = console

appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

rootLogger.level = debug
rootLogger.appenderRefs = stdout
rootLogger.appenderRef.stdout.ref = STDOUT

【问题讨论】:

    标签: eclipse spring-boot gradle log4j log4j2


    【解决方案1】:

    Spring Boot 使用 Logback 作为日志框架。

    如果你想使用 Log4j2 你必须做一些配置。

    排除默认记录器并添加log4j2启动器依赖:

    dependencies {
        compile 'org.springframework.boot:spring-boot-starter-web'
        compile 'org.springframework.boot:spring-boot-starter-log4j2'
    }
    
    configurations {
        all {
            exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
        }
    }
    

    据我所知,Log4j2 是使用 XML 文件而不是属性文件配置的。

    请在官方 Spring Boot 参考文档中找到所有信息:

    https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-configure-log4j-for-logging

    【讨论】:

      猜你喜欢
      • 2017-09-07
      • 2018-06-12
      • 1970-01-01
      • 1970-01-01
      • 2018-06-14
      • 2019-08-31
      • 2019-05-19
      • 1970-01-01
      • 2017-03-15
      相关资源
      最近更新 更多