zoukankan      html  css  js  c++  java
  • 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");
        }
  • 相关阅读:
    hdu2066最短路径spfa算法对每个点分别判断0ms过
    关于oj上c++与g++的区别以及一些常见的问题
    hdu1213依旧并查集。求集合的个数
    hdu2112最短路径
    hdu1232最水并查集模版题
    hdu1325最大联通分量+树中点与边数值关系
    hdu2544最短路径spfa模版题
    hdu1856依旧并查集
    hdu1879最小生成树+并查集
    sencha touch 视图(view) show与hide事件探讨
  • 原文地址:https://www.cnblogs.com/bwcode/p/7159624.html
Copyright © 2011-2022 走看看