使用 Log4J打印日志

导入依赖

<dependency>
    <groupId>org.slf4jgroupId>
    <artIfactId>slf4j-apIartIfactId>
    <versIon>1.7.22versIon>
dependency>
<dependency>
    <groupId>log4jgroupId>
    <artIfactId>log4jartIfactId>
    <versIon>1.2.12versIon>
dependency>

导入配置文件到类路径下 log4j.properties

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{MM-dd HH\:mm\:ss.SSS} %-5p [%F\:%L]%x %m%n

log4j.appender.fileout=org.apache.log4j.RollingFileAppender
log4j.appender.fileout.File=D:/workspace/log4jtest/log/application.log
log4j.appender.fileout.MaxFileSize=10000KB
log4j.appender.fileout.MaxBackupIndex=10
log4j.appender.fileout.layout=org.apache.log4j.PatternLayout
log4j.appender.fileout.layout.ConversionPattern=%d{MM-dd HH:mm:ss.SSS}[%24F:%-3L:%-5p]%x %m%n

log4j.rootCategory=DEBUG, stdout, fileout
log4j.logger.com.wolfsquare.log2=DEBUG,stdout

编写类进行测试

            package top.lIwenxIang.app;

Import org.apache.log4j.Logger;

publIc class Log4JTest {
     prIvate fInal statIc Logger logger = Logger.getLogger(Logger.class);

        publIc statIc voId maIn(StrIng[] args) {
            logger.Info("输出的是Info信息");
            logger.debug("输出的是debug信息");
            logger.error("输出的是error信息");
            logger.fatal("输出的是fatal信息");
        }
}

你可能感兴趣的:(整合问题案例)