#rootLogger参数分别为: 根Logger级别, 输出器stdout, 输出器log log4j.rootLogger = info,stdout,log # \u8F93\u51FA\u4FE1\u606F\u5230\u63A7\u5236\u53F0 log4j.appender.stdout = org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout = org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern = %d [%-5p] %l %rms: %m%n #输出DEBUG级别以上的日志到D: //logs/debug.log log4j.appender.log = org.apache.log4j.DailyRollingFileAppender log4j.appender.log.DatePattern = '.'yyyy-MM-dd log4j.appender.log.File = D://debug.log log4j.appender.log.Encoding = UTF-8 #log4j.appender.log.Threshold = INFO log4j.appender.log.layout = org.apache.log4j.PatternLayout log4j.appender.log.layout.ConversionPattern = %d [%-5p] (%c.%t): %m%n
测试一下
public class Log4jTest { // public static Logger log = Logger.getLogger(Log4jTest.class); private static final Logger logger = LoggerFactory .getLogger(Log4jTest.class); public static void main(String[] args) { logger.info("Current Time: {}", System.currentTimeMillis()); logger.info("Current Time: " + System.currentTimeMillis()); logger.info("Current Time: {}", System.currentTimeMillis()); logger.trace("trace log"); logger.warn("warn log"); logger.debug("debug log"); logger.info("info log"); logger.error("error log"); logger.info("current time :{}", System.currentTimeMillis()); logger.error("error"); logger.info("这是我要输出的日志"); System.out.println("打印结果"); // 以下是log4j用法 // log.debug("debug信息"); // log.info("info信息"); // log.warn("this is warm"); } }