#记录程序中的WARN信息
log4j.rootLogger=WARN,fstic,fstifile
# R is set to be a DailyRollingFileAppender.
#log4j.appender.fstifile=org.apache.log4j.DailyRollingFileAppender
#log4j.appender.fstifile.File=../fsti.log
#log4j.appender.fstifile.DatePattern = '.'yyyy-MM-dd
#log4j.appender.fstifile.layout=org.apache.log4j.PatternLayout
#log4j.appender.fstifile.layout.ConversionPattern=%p: %d{yyyy-MM-dd HH:mm:ss,SSS}[%t][%l]- %m%n
log4j.appender.fstic=org.apache.log4j.ConsoleAppender
log4j.appender.fstic.layout=org.apache.log4j.PatternLayout
log4j.appender.fstic.layout.ConversionPattern=%p: %d{yyyy-MM-dd HH:mm:ss,SSS}[%t][%l]- %m%n
------------------------------------------
TestAction.jsp
------------------------------
<%@ page import="org.apache.commons.logging.Log" %>
<%@ page import="org.apache.commons.logging.LogFactory" %>
private static Log log = LogFactory.getLog(TestAction.class.getName());
log.error(e.getMessage(),e);
log4j.rootLogger=WARN,fstic,fstifile
# R is set to be a DailyRollingFileAppender.
#log4j.appender.fstifile=org.apache.log4j.DailyRollingFileAppender
#log4j.appender.fstifile.File=../fsti.log
#log4j.appender.fstifile.DatePattern = '.'yyyy-MM-dd
#log4j.appender.fstifile.layout=org.apache.log4j.PatternLayout
#log4j.appender.fstifile.layout.ConversionPattern=%p: %d{yyyy-MM-dd HH:mm:ss,SSS}[%t][%l]- %m%n
log4j.appender.fstic=org.apache.log4j.ConsoleAppender
log4j.appender.fstic.layout=org.apache.log4j.PatternLayout
log4j.appender.fstic.layout.ConversionPattern=%p: %d{yyyy-MM-dd HH:mm:ss,SSS}[%t][%l]- %m%n
------------------------------------------
TestAction.jsp
------------------------------
<%@ page import="org.apache.commons.logging.Log" %>
<%@ page import="org.apache.commons.logging.LogFactory" %>
private static Log log = LogFactory.getLog(TestAction.class.getName());
log.error(e.getMessage(),e);
本文介绍如何使用Log4j配置文件设置日志记录级别为WARN,并详细展示了配置文件的具体内容,包括定义了文件滚动策略及控制台输出格式。

被折叠的 条评论
为什么被折叠?



