我有一个测试类,可以在其中打印所有日志。但仅打印错误。
package com.testClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Test {
public static Logger logger =
LoggerFactory.getLogger(Test.class);
public static void main(String[] args) {
logger.debug("This is debug message");
logger.info("This is info message");
logger.warn("This is warn message");
logger.error("This is error message");
}
}
仅控制台输出-
18:12:08.938 [main] ERROR com.testClass.Test - This is error message
这里是属性
log4j.rootCategory=ALL, console-log, file
log4j.appender.console-log=org.apache.log4j.ConsoleAppender
log4j.appender.console-log.Target=System.out
log4j.appender.console-log.layout=org.apache.log4j.PatternLayout
log4j.appender.console-log.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=./logs/asgard_service.log
log4j.appender.file.MaxFileSize=12MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.appender.job-log=org.apache.log4j.RollingFileAppender
log4j.appender.job-log.File=./logs/asgard-job.log
log4j.appender.job-log.layout=org.apache.log4j.PatternLayout
log4j.appender.job-log.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n