## LOGGERS ## #define a logger #log4j.rootLogger=DEBUG,console,file log4j.rootLogger=INFO,console,file ## APPENDERS ## # define an appender named console, which is set to be a ConsoleAppender log4j.appender.console=org.apache.log4j.ConsoleAppender # define an appender named file, which is set to be a RollingFileAppender log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.File=${catalina.base}/logs/2009.log #set the log's size log4j.appender.file.MaxFileSize=1000KB log4j.appender.file.MaxBackupIndex=20 ## LAYOUTS ## # assign a SimpleLayout to console appender log4j.appender.console.layout=org.apache.log4j.SimpleLayout # assign a PatternLayout to file appender log4j.appender.file.layout=org.apache.log4j.PatternLayout # For debug # log4j.appender.file.layout.ConversionPattern=[%-5p][%t][%C][%d{yyyy-MM-dd HH:mm:ss}] %m%n # For deployment log4j.appender.file.layout.ConversionPattern=[%-5p][%d{yyyy-MM-dd HH:mm:ss}] %m%n
常用输出格式
# -X:X信息输出时左对齐;
# %p:日志信息级别
# %d{}:日志信息产生时间
# %c:日志信息所在地(类名)
# %m:产生的日志具体信息
# %n:输出日志信息换行
Logger logger = Logger.getLogger(TestLog4j.class);
Log4j建议只使用四个级别,优先级从高到低:ERROR、WARN、INFO、DEBUG