Website
Http://log4mongo.org/display/PUB/Log4mongo+for+Java
Save host information, methods, etc.
http://my.oschina.net/chinaearl/blog/111552
Save output information only
Http://www.myexception.cn/program/650442.html
Configuration
Log4j.rootlogger=info, stdout
Log4j.appender.stdout=org.apache.log4j.consoleappender
Log4j.appender.stdout.layout=org.apache.log4j.patternlayout
Log4j.logger.mongodb=info,mongodb
Log4j.appender.mongodb=org.log4mongo.mongodbpatternlayoutappender
Log4j.appender.mongodb.threshold=info
Log4j.appender.mongodb.databasename=mydb
Log4j.appender.mongodb.collectionname=optlog
log4j.appender.mongodb.hostname=10.25.193.16
log4j.appender.mongodb.port=9933
Log4j.appender.mongodb.layout=org.log4mongo.mongodbpatternlayout
Log4j.logger.mongodb2=info,mongodb2
Log4j.appender.mongodb2=org.log4mongo.mongodbpatternlayoutappender
Log4j.appender.mongodb2.threshold=info
Log4j.appender.mongodb2.databasename=mydb
Log4j.appender.mongodb2.collectionname=abclog
log4j.appender.mongodb2.hostname=10.25.193.16
log4j.appender.mongodb2.port=9933
Log4j.appender.mongodb2.layout=org.log4mongo.mongodbpatternlayout
Class
public static void Main (string[] args) {
Logger Logger = Logger.getlogger ("MongoDB");
Logger.info ("{' Provincecode ': null, ' Channelsubcode ': null, ' Platformcode ': ' 002 ', ' OptCode ': null, ' Starttimelong ': 1384599600000, ' processtime_sum ': 10081, ' count ': 404, ' Suc_count ': 0, ' suc_rate ': ' 0.00000 '} ';
Logger logger2 = Logger.getlogger ("MongoDB2");
Logger2.info ("{' Provincecode ': 123}");
}
log4j Output information to MongoDB