mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-07-27 07:45:41 +00:00
add localfile recorder
This commit is contained in:
@@ -2,12 +2,41 @@
|
||||
var zlib = require('zlib'),
|
||||
Datastore = require('nedb'),
|
||||
util = require("util"),
|
||||
events = require('events'),
|
||||
db = new Datastore(); //in-memory store
|
||||
fs = require("fs"),
|
||||
events = require('events');
|
||||
|
||||
function Recorder(){
|
||||
//option.filename
|
||||
function Recorder(option){
|
||||
var self = this,
|
||||
id = 1;
|
||||
id = 1,
|
||||
db;
|
||||
|
||||
option = option || {};
|
||||
if(option.filename){
|
||||
|
||||
try{
|
||||
if(fs.existsSync(option.filename)){
|
||||
fs.writeFileSync(option.filename,""); //empty original file
|
||||
}
|
||||
|
||||
db = new Datastore({
|
||||
filename : option.filename,
|
||||
autoload :true
|
||||
});
|
||||
db.persistence.setAutocompactionInterval(5001);
|
||||
console.log("db file : " + option.filename);
|
||||
|
||||
}catch(e){
|
||||
console.log(e);
|
||||
console.log("Failed to load on-disk db file. Will use in-meomory db instead.");
|
||||
db = new Datastore();
|
||||
}
|
||||
|
||||
}else{
|
||||
//in-memory db
|
||||
db = new Datastore();
|
||||
}
|
||||
|
||||
|
||||
self.recordBodyMap = []; // id - body
|
||||
|
||||
@@ -64,6 +93,9 @@ function Recorder(){
|
||||
self.getSummaryList = function(cb){
|
||||
db.find({},cb);
|
||||
};
|
||||
|
||||
|
||||
self.db = db;
|
||||
}
|
||||
|
||||
util.inherits(Recorder, events.EventEmitter);
|
||||
|
Reference in New Issue
Block a user