log4j 日志 保存到数据库
################################# # 保存到数据库 ################################# log4j.logger.db=info,db log4j.appender.db=org.apache.log4j.jdbc.JDBCAppender log4j.appender.db.driver=com.mysql.jdbc.Driver log4j.appender.db.URL=jdbc:mysql://192.168.1.151:3306/xiaokuaimei_pc?autoReconnect=true&failOverReadOnly=false&maxReconnects=10 log4j.appender.db.user=root log4j.appender.db.password=root log4j.appender.db.sql=insert into s_log (className,methodName,createTime,logLevel,message) values ('%C','%M','%d{yyyy-MM-dd HH:mm:ss}','%p','%m') log4j.appender.db.layout=org.apache.log4j.PatternLayout
java 里面就是
public class TestLog { private static Log log = LogFactory.getLog("db"); @Test public void test1(){ for(int i=0;i<1000;i++) { log.info("1"); log.info("2"); log.info("3"); log.info("5"); log.info("4"); } } }
就可以了