|
|
@ -101,15 +101,39 @@ var fs = require('fs'),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
events.getLog = function(callback) {
|
|
|
|
events.getLog = function(end, len, callback) {
|
|
|
|
var logFile = path.join(nconf.get('base_dir'), logFileName);
|
|
|
|
var logFile = path.join(nconf.get('base_dir'), logFileName);
|
|
|
|
|
|
|
|
|
|
|
|
fs.readFile(logFile, function(err, res) {
|
|
|
|
fs.stat(logFile, function(err, stat) {
|
|
|
|
if(err) {
|
|
|
|
if (err) {
|
|
|
|
return callback(null, 'No logs found!');
|
|
|
|
return callback(null, 'No logs found!');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
callback(null, res);
|
|
|
|
|
|
|
|
|
|
|
|
var buffer = '';
|
|
|
|
|
|
|
|
var size = stat.size;
|
|
|
|
|
|
|
|
if (end === -1) {
|
|
|
|
|
|
|
|
end = size;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end = parseInt(end, 10);
|
|
|
|
|
|
|
|
var start = Math.max(0, end - len);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var rs = fs.createReadStream(logFile, {start: start, end: end});
|
|
|
|
|
|
|
|
rs.addListener('data', function(lines) {
|
|
|
|
|
|
|
|
buffer += lines.toString();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rs.addListener('end', function() {
|
|
|
|
|
|
|
|
var firstNewline = buffer.indexOf('\n');
|
|
|
|
|
|
|
|
if (firstNewline !== -1) {
|
|
|
|
|
|
|
|
buffer = buffer.slice(firstNewline);
|
|
|
|
|
|
|
|
buffer = buffer.split('\n').reverse().join('\n');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
callback(null, {data: buffer, next: end - buffer.length});
|
|
|
|
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}(module.exports));
|
|
|
|
}(module.exports));
|
|
|
|