小编Gur*_*ngh的帖子

Spring boot 不搜索 log4j2 配置文件

我正在尝试将 Apache Log4j 2.12.1 与 Spring Boot 2.2.1 一起使用,但是当我运行时,它没有给出有关缺少 log4j 2 配置文件的任何警告。下面是日志的代码(简单的一次类来测试它是否有效或注意):

package com.example.Log4jdemoSpringboot;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Log4jDemoSpringBootApplication {

    static Logger logger = LogManager.getLogger(Log4jDemoSpringBootApplication.class);
    public static void main(String[] args) {
        SpringApplication.run(Log4jDemoSpringBootApplication.class, args);
        logger.info("info");
        logger.warn("warn");
        logger.error("error");
        logger.debug("debug");
        logger.fatal("fatal");
    }

}
Run Code Online (Sandbox Code Playgroud)

以下是输出:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ …
Run Code Online (Sandbox Code Playgroud)

java spring log4j2 spring-boot

3
推荐指数
3
解决办法
3448
查看次数

标签 统计

java ×1

log4j2 ×1

spring ×1

spring-boot ×1