# 设置日志文件存放的路径 log=E:\workspacne_JDK8Tomcat8.5\Log4jDemo # Define the root logger with appender file log4j.rootLogger = DEBUG, FILE # Define the file appender log4j.appender.FILE=org.apache.log4j.FileAppender # file name log4j.appender.FILE.File=${log}/log.out # Set the flush to true log4j.appender.FILE.ImmediateFlush=true # Set the threshold to debug mode log4j.appender.FILE.Threshold=debug # Set the append to true, overwrite log4j.appender.FILE.Append=true # Define the layout for file appender log4j.appender.FILE.layout=org.apache.log4j.PatternLayout log4j.appender.FILE.layout.conversionPattern=%m%n
static { System.setProperty("log", "E:/workspacne_JDK8Tomcat8.5/Log4jDemo"); } /* Get actual class name to be printed on */ staticLoggerlog= Logger.getLogger(Log4jExample.class.getName());
publicstaticvoidmain(String[] args)throws IOException, SQLException { log.debug("Hello this is a debug message"); log.info("Hello this is an info message"); } }