zoukankan      html  css  js  c++  java
  • idea maven整合log4j

    pom.xml:

    <dependencies>
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.17</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>1.7.25</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
                <version>1.7.25</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-simple</artifactId>
                <version>1.7.25</version>
            </dependency>
        </dependencies>

    log4j.properties:

    ### 设置###
    log4j.rootLogger = info,stdout,D,E
    
    ### 输出信息到控制台 ###
    log4j.appender.stdout = org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.Target = System.out
    log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
    
    ### 输出DEBUG 级别以上的日志到=E://logs/debug.log ###
    log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
    log4j.appender.D.File = E://JE_Project/logs/debug.log           //日志输出路径 可更改
    log4j.appender.D.Append = true
    log4j.appender.D.Threshold = DEBUG
    log4j.appender.D.layout = org.apache.log4j.PatternLayout
    log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n
    
    ### 输出ERROR 级别以上的日志到=E://logs/error.log ###
    log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
    log4j.appender.E.File =E://JE_Project/logs/error.log
    log4j.appender.E.Append = true
    log4j.appender.E.Threshold = ERROR
    log4j.appender.E.layout = org.apache.log4j.PatternLayout
    log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n

    helloworld.java:

    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    public class HelloWorld {
    
        private static final Logger log = LoggerFactory.getLogger(HelloWorld.class);
    
        public static void main(String[] args) {
            log.debug("rgwegwegwegwegwe");
            log.info("rgwegwegwegwegwe");
            log.error("rgwegwegwegwegwe");
    
            System.out.println("5135354354354");
        }
    }

    完成

  • 相关阅读:
    ubuntu 安装eclipse
    java中的ArrayList 、List、LinkedList、Collection关系详解
    JERSEY中文翻译(第三章、模块和依赖)
    JERSEY中文翻译(第一章、Getting Started、2.2)
    JERSEY中文翻译(第三章、JAX-RS Application, Resources and Sub-Resources)
    JERSEY中文翻译(第一章、Getting Started、1.1.7)
    创建一个入门的JAVA WEB站点(REST JERSEY)
    一个JAVA的WEB服务器事例
    一个简单的C/S事例——JAVA-Socket
    FILTER——JAVA
  • 原文地址:https://www.cnblogs.com/chong-zuo3322/p/13787256.html
Copyright © 2011-2022 走看看