• SpringBoot使用log4j2


    先在maven里把spring-boot-starter里的spring-boot-starter-logging依赖去掉

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-logging</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>

    添加log4j2的依赖

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-log4j2</artifactId>
            </dependency>

    在application.yml里配置日志设置文件

    logging:
      config: classpath:log4j2.properties

    log4j2.properties内容

    status = warn
    name = MyApp
    
    filter.threshold.type = ThresholdFilter
    filter.threshold.level = debug
    
    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 ] %m (%c:%L)%n
    
    appender.rolling.type = File
    appender.rolling.name = log
    appender.rolling.append = true
    appender.rolling.fileName = d:\test1.log
    appender.rolling.layout.type = PatternLayout
    appender.rolling.layout.pattern =  %-d{yyyy-MM-dd HH:mm:ss} [ %-5p ] %m (%c:%L)%n
    
    rootLogger.level = debug
    rootLogger.appenderRef.stdout.ref = STDOUT
    rootLogger.appenderRef.log.ref = log

    log4j2的官方文档logging.apache.org/log4j/2.x/index.html

  • 相关阅读:
    IDEA创建一个javaweb工程(在module中)以及配置Tomcat
    晨会复盘
    cnblog 笔记思路
    Mysql执行计划-extra
    Mysql执行计划分析-type(access_type)
    Mysql执行计划-selectType
    刻意训练
    MYSQL执行计划
    个人展望-程序员职业规划
    服务拆分原则
  • 原文地址:https://www.cnblogs.com/A-yes/p/9894150.html
Copyright © 2020-2023  润新知