commons-logging.properties文件
##org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
Log4j.properties文件
## LOGGERS ##
# define a logger named helloAppLogger
log4j.rootLogger=INFO,console,file #日志级别为Info
## 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=M:\\myserver.log #日志写入文件
## 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
log4j.appender.file.layout.ConversionPattern==%d{yyyy MMM dd HH:mm:ss} %-5p %c - %m%n #日志输出日期格式
simplelog.properties
#Tue Feb 07 11:31:28 CST 2006
org.apache.commons.logging.simplelog.defaultlog=info
这3个文件直接放在你src目录下就可以了.
类里这么调用
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Log log = LogFactory.getLog("XXX");
log.info("log message");
posted on 2006-10-19 12:10
aiyoyoyo 阅读(155)
评论(0) 编辑 收藏 所属分类:
Log4J