# 用于数据库
log4j.rootLogger=info,db
log4j.appender.db=org.apache.log4j.jdbc.JDBCAppender
log4j.appender.db.driver=com.mysql.jdbc.Driver
log4j.appender.db.URL=jdbc:mysql://localhost:3306/test
log4j.appender.db.user=root
log4j.appender.db.password=root
log4j.appender.db.sql=INSERT INTO LOG(Message) VALUES ('%m')
log4j.appender.db.layout=org.apache.log4j.PatternLayout
实现:
public class Test {
static Logger logger = Logger.getLogger(Test.class.getName());
public static void main(String[] args) {
PropertyConfigurator.configure ( "f:/work/jbuildup/src/com/yss/log4j/log4j.properties" ) ;
// MDC.put("userId", "lk");
// MDC.put("userName", "lk"); 设置另外的属性值
logger.debug("ad info");
logger.info("I have come in!");
logger.warn("warn info");
logger.error("error info");
logger.fatal("fatal info");
}
}