pomelo
Version:
Pomelo is a fast, scalable game server framework for [node.js](http://nodejs.org). It provides the basic development framework and many related components, including libraries and tools. Pomelo is also suitable for real-time web applications; its distri
45 lines (38 loc) • 955 B
JavaScript
/**
* Filter for rpc log.
* Record used time for remote process call.
*/
var rpcLogger = require('pomelo-logger').getLogger('rpc-log', __filename);
var utils = require('../../util/utils');
module.exports = function() {
return new Filter();
};
var Filter = function () {
};
Filter.prototype.name = 'rpcLog';
/**
* Before filter for rpc
*/
Filter.prototype.before = function(serverId, msg, opts, next) {
opts = opts||{};
opts.__start_time__ = Date.now();
next();
};
/**
* After filter for rpc
*/
Filter.prototype.after = function(serverId, msg, opts, next) {
if(!!opts && !!opts.__start_time__) {
var start = opts.__start_time__;
var end = Date.now();
var timeUsed = end - start;
var log = {
route: msg.service,
args: msg.args,
time: utils.format(new Date(start)),
timeUsed: timeUsed
};
rpcLogger.info(JSON.stringify(log));
}
next();
};