• SpringBoot集成log4j


    1、pom.xml中增加依赖

    <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>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j</artifactId>
        <version>1.3.8.RELEASE</version>
    </dependency>
    

    说明:去除对默认日志的依赖,是为了去除和logback的冲突。

    2、在resources目录下添加log4j.properties文件

    log4j.rootLogger=info,R,R2,R3
    log4j.logger.monitor = info,monitor
    log4j.logger.time-consuming = info,time-consuming
    ##log4j.rootLogger=info,errorservice,CONSOLE,DEBUG
    #
    ##print to console
    #-----------------------   CONSOLE   -------------------------------------------------
    log4j.appender.R=org.apache.log4j.ConsoleAppender
    log4j.appender.R.Target=System.out
    log4j.appender.R.ImmediateFlush=true
    log4j.appender.R.Threshold=info
    log4j.appender.R.layout=org.apache.log4j.PatternLayout
    log4j.appender.R.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}:  %m%n
    
    
    #--------------------------------   INFO   -------------------------------------------
    log4j.appender.R2=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.R2.DatePattern='.'yyyy-MM-dd-HH
    log4j.appender.R2.File=/data/mmmeditor/info.log
    #log4j.appender.R2.File=D:/workspace/info.log
    log4j.appender.R2.Threshold=info
    log4j.appender.R2.ImmediateFlush=true
    log4j.appender.R2.Append=true
    log4j.appender.R2.layout=org.apache.log4j.PatternLayout
    log4j.appender.R2.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS}:  %m%n
    log4j.additivity.R2=false
    
    
    #write to file on the level of error
    #-----------------------   error  ---------------------------------
    log4j.appender.R3=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.R3.DatePattern='.'yyyy-MM-dd-HH
    log4j.appender.R3.File=/data/mmmeditor/error.log
    #log4j.appender.R3.File=D:/workspace/error.log
    log4j.appender.R3.Threshold=error
    log4j.appender.R3.ImmediateFlush=true
    log4j.appender.R3.Append=true
    log4j.appender.R3.layout=org.apache.log4j.PatternLayout
    log4j.appender.R3.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS}:  %m%n
    log4j.additivity.R3=false
    
    
    #------------------ 修改 /data/mmmeditor/time-consuming.log ----------------------
    log4j.appender.monitor=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.monitor.DatePattern='.'yyyy-MM-dd
    log4j.appender.monitor.layout.ConversionPattern={"level":"%p","timestamp":"%d{yyyy-MM-dd HH:mm:ss,SSS}","thread":"%t","file":"%F","number":"%L","class":"%C","method":"%M","message":%m}%n
    log4j.appender.monitor.File=/data/mmmeditor/monitor.log
    #log4j.appender.monitor.File=D:/mylog/monitor.log
    log4j.appender.monitor.MaxFileSize=10000KB
    log4j.appender.monitor.MaxBackupIndex=1
    log4j.appender.monitor.layout=org.apache.log4j.PatternLayout
    log4j.additivity.monitor=false
    
    
    #------------------ 修改 /data/mmmeditor/time-consuming.log -----------------------
    log4j.appender.time-consuming=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.time-consuming.DatePattern='.'yyyy-MM-dd
    log4j.appender.time-consuming.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}[%t]: %m%n
    log4j.appender.time-consuming.File=/data/mmmeditor/time-consuming.log
    #log4j.appender.time-consuming.File=D:/mylog/time-consuming.log
    log4j.appender.time-consuming.MaxFileSize=10000KB
    log4j.appender.time-consuming.MaxBackupIndex=1
    log4j.appender.time-consuming.layout=org.apache.log4j.PatternLayout
    #log4j.additivity.time-consuming=false
    

    注意:修改/data/mmmeditor/time-consuming.log

  • 相关阅读:
    浅析Go中的MPG模式(一)
    panic: assignment to entry in nil map
    Golang 新手可能会踩的 50 个坑
    小刘的go面试题
    go 单元测试整理
    go test 测试单个文件和测试单个函数
    mac pro锁屏后没有声音了怎么处理
    go json返回时间字符串处理time.Time类型
    php求一个字符串中不重复的最长子串
    业务订单号生成算法,每秒50W左右,不同机器保证不重复,包含日期可读性好
  • 原文地址:https://www.cnblogs.com/songjn/p/13364826.html
Copyright © 2020-2023  润新知