• maven 中 slf4j的使用


     Maven web 项目中日志记录

    1.pom.xml中引用

            <!-- log -->
            <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>1.7.25</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
                <version>1.7.25</version>
                <!-- <scope>test</scope> -->
            </dependency>

    2.日志配置log4j.properties

    log4j.rootLogger=CONSOLE,FILE
    log4j.addivity.org.apache=true
    
    # 应用于控制台
    log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
    log4j.appender.CONSOLE.Threshold=INFO
    log4j.appender.CONSOLE.Target=System.out
    log4j.appender.CONSOLE.Encoding=UTF-8
    log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
    log4j.appender.CONSOLE.layout.ConversionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n
    
    # 每天新建日志
    log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.A1.File=D:/log4j/log
    log4j.appender.A1.Encoding=UTF-8
    log4j.appender.A1.Threshold=DEBUG
    log4j.appender.A1.DatePattern='.'yyyy-MM-dd
    log4j.appender.A1.layout=org.apache.log4j.PatternLayout
    log4j.appender.A1.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L : %m%n
    
    #应用于文件
    log4j.appender.FILE=org.apache.log4j.FileAppender
    log4j.appender.FILE.File=E:/log4j/file.log
    log4j.appender.FILE.Append=false
    log4j.appender.FILE.Encoding=UTF-8
    log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
    log4j.appender.FILE.layout.ConversionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n

     3.代码中使用

        private static final Logger log = LoggerFactory.getLogger(AppLog.class);
    
        public static void main(String[] args) {
            
            log.debug("debug");
            log.info("info");
            log.error("error");
        }
  • 相关阅读:
    链式队列(先进先出)
    单链表的基本操作
    线性表的基本操作
    面向对象分析与设计
    结构化分析与设计
    图片
    2021-ACM-ICPC-济南站 K Search For Mafuyu 【树的遍历与回溯,dfs, 邻接表】
    Codeforces Round #754 (Div. 2), problem: (A) A.M. Deviation泪目 万万没想到狂wa是因为这
    Codeforces Round #704 (Div. 2), problem: (C) Maximum width还是要多学习
    Educational Codeforces Round 116 (Rated for Div. 2), problem: (C) Banknotes
  • 原文地址:https://www.cnblogs.com/bwcode/p/7159624.html
Copyright © 2020-2023  润新知