# Define the root logger with appender file log4j.rootLogger = DEBUG, FILE # Define the file appender log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender # Set the name of the file #log4j.appender.FILE.File=${log}/log.out log4j.appender.FILE.File=log.out # Set the immediate flush to true (default) log4j.appender.FILE.ImmediateFlush=true # Set the threshold to debug mode log4j.appender.FILE.Threshold=debug # Set the append to false, should not overwrite log4j.appender.FILE.Append=true # Set the DatePattern log4j.appender.FILE.DatePattern='.' yyyy-MM-dd-a # Define the layout for file appender log4j.appender.FILE.layout=org.apache.log4j.PatternLayout log4j.appender.FILE.layout.conversionPattern=%m%n
# Define the root logger with appender file log4j.rootLogger = DEBUG, FILE # Define the file appender log4j.appender.FILE=org.apache.log4j.RollingFileAppender # Set the name of the file log4j.appender.FILE.File=log.out # Set the immediate flush to true (default) log4j.appender.FILE.ImmediateFlush=true # Set the threshold to debug mode log4j.appender.FILE.Threshold=debug # Set the append to false, should not overwrite log4j.appender.FILE.Append=true # Set the maximum file size before rollover log4j.appender.FILE.MaxFileSize=5KB # Set the the backup index log4j.appender.FILE.MaxBackupIndex=2 # Define the layout for file appender log4j.appender.FILE.layout=org.apache.log4j.PatternLayout log4j.appender.FILE.layout.conversionPattern=%m%n
# 设置日志文件存放的路径 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"); } }
publicclassLog4jExample { /* 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"); } }
# Define the root logger with appender XXX
log4j.rootLogger = DEBUG, XXX
# Set the appender named XXX to be a File appender
log4j.appender.XXX=org.apache.log4j.FileAppender
# Define the layout for XXX appender
log4j.appender.XXX.layout=org.apache.log4j.PatternLayout
log4j.appender.XXX.layout.conversionPattern=%m%n