• log4j Test


    package test;
    
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    
    public class Log4jTest {
        private static Log logger = LogFactory.getLog(Log4jTest.class); 
        public static void main(String[] args) {
            logger.error("ERROR");
            logger.debug("DEBUG");
            logger.warn("WARN");
            logger.info("INFO");
            logger.trace("TRACE");
            System.out.println(logger.getClass());
        }
    
    }

    1 将commons-logging-1.0.4.jar,log4j.jar放入新建文件夹lib下,然后选中二者,build path 后,classpath发生了改变

    <?xml version="1.0" encoding="UTF-8"?>
    <classpath>
        <classpathentry kind="src" path="src"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
        <classpathentry kind="lib" path="lib/commons-logging-1.0.4.jar"/>
        <classpathentry kind="lib" path="lib/log4j.jar"/>
        <classpathentry kind="output" path="bin"/>
    </classpath>

    2 添加 \bin\log4j.properties

    # log4j configuration used during build and unit tests
    
    log4j.rootLogger=info,stdout,R
    log4j.threshhold=ALL
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern=%d{ISO8601} %-5p %c{2} (%F:%M(%L)) - %m%n
    
    log4j.appender.R=org.apache.log4j.RollingFileAppender
    log4j.appender.R.File=test.txt
    log4j.appender.R.MaxFileSize=100KB
    log4j.appender.R.MaxBackupIndex=0
    log4j.appender.R.layout=org.apache.log4j.PatternLayout
    log4j.appender.R.layout.ConversionPattern=%d{ISO8601} %-5p %c{2} (%F:%M(%L)) - %m%n

    运行,日志文件位置:log4jtest\test.txt

  • 相关阅读:
    2019 牛客多校第五场 B generator 1
    POJ 1797 Heavy Transportation
    POJ 3352 Road Construction
    POJ 2553 The Bottom of a Graph
    POJ 1236 Network of Schools
    POJ 1144 Network
    POJ 3761 Bubble Sort
    2019 牛客多校第三场 B Crazy Binary String
    2019 牛客多校第三场 H Magic Line
    Codeforces Round #592 (Div. 2)
  • 原文地址:https://www.cnblogs.com/i80386/p/2636299.html
Copyright © 2020-2023  润新知