LOG4J Mysql

1719 ワード

詳細

CREATE TABLE `log` (
  `class` varchar(100) DEFAULT NULL,
  `method` varchar(64) DEFAULT NULL,
  `createtime` varchar(32) DEFAULT NULL,
  `loglevel` varchar(8) DEFAULT NULL,
  `msg` varchar(255) DEFAULT NULL,
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `line` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8
log4j.rootLogger=INFO,database,stdout

###             ###
#          
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
#     System.out  
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
#      :     log  
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}  %m%n

###            ###
log4j.appender.database=org.apache.log4j.ConsoleAppender
log4j.appender.database.layout=org.apache.log4j.PatternLayout
log4j.appender.database.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss:SSS}[%p]: %m%n

log4j.appender.database=org.apache.log4j.jdbc.JDBCAppender
log4j.appender.database.driver=com.mysql.jdbc.Driver
log4j.appender.database.URL=jdbc:mysql://localhost:3306/logdb?useUnicode=true&characterEncoding=UTF-8
log4j.appender.database.user=root
log4j.appender.database.password=123456
log4j.appender.database.sql=insert into log (class,method,createtime,loglevel,msg,line) VALUES ('%C','%M','%d{yyyy-MM-dd hh:mm:ss}','%p','%m','%l')
log4j.appender.database.layout=org.apache.log4j.PatternLayout