Kouhei Sutou
null+****@clear*****
Sun Jul 21 16:36:09 JST 2013
Kouhei Sutou 2013-07-21 16:36:09 +0900 (Sun, 21 Jul 2013) New Revision: 83b6c6071caf439d28c1aa5d85dc68b87115e3b7 https://github.com/groonga/express-droonga/commit/83b6c6071caf439d28c1aa5d85dc68b87115e3b7 Message: connection: add debug logs Modified files: lib/backend/connection.js Modified: lib/backend/connection.js (+12 -2) =================================================================== --- lib/backend/connection.js 2013-07-21 16:34:05 +0900 (0cf0d63) +++ lib/backend/connection.js 2013-07-21 16:36:09 +0900 (0498ad3) @@ -9,6 +9,7 @@ var EventEmitter = require('events').EventEmitter; var fluent = require('fluent-logger'); var FluentReceiver = require('./receiver').FluentReceiver; +var debug = require('../debug'); var DEFAULT_FLUENT_TAG = Connection.DEFAULT_FLUENT_TAG = @@ -65,8 +66,11 @@ Connection.prototype._initReceiver = function() { this.receivePort = receiver.port; }).bind(this)); + var tag = this.tag + '.message'; + debug('Connection._initReceiver %d: %d %d:', + this._id, receiver._id, this.receivePort, tag); this._receiver = receiver; - this._receiver.on(this.tag + '.message', + this._receiver.on(tag, this._handleMessage.bind(this)); }; @@ -77,11 +81,13 @@ function isSuccess(code) { Connection.prototype._handleMessage = function(envelope) { var inReplyTo = envelope.inReplyTo; if (inReplyTo) { + debug('Connection._handleMessage.reply %d:', this._id, inReplyTo); var errorCode = envelope.statusCode; if (!errorCode || isSuccess(errorCode)) errorCode = null; this.emit('reply:' + inReplyTo, errorCode, envelope); } else { + debug('Connection._handleMessage.message %d:', this._id, envelope.type); this.emit(envelope.type, envelope.body); } }; @@ -112,6 +118,7 @@ function toPositiveInteger(number) { Connection.prototype.emitMessage = function(type, body, callback, options) { options = options || {}; var id = createId(); + debug('Connection.emitMessage %d:', this._id, id, type); var replyTo = this.receiveHostName + ':' + this.receivePort + '/' + this.tag + '?connection_id=' + this._id; if (options.sessionId) @@ -126,7 +133,10 @@ Connection.prototype.emitMessage = function(type, body, callback, options) { }; if (callback) { var event = 'reply:' + id; - this.once(event, callback); + this.once(event, function(errorCode, response) { + debug('Connection.emitMessage.reply %d:', this._id, errorCode); + callback(errorCode, response); + }); options.timeout = toPositiveInteger(options.timeout) || DEFAULT_RESPONSE_TIMEOUT; setTimeout((function() { -------------- next part -------------- HTML����������������������������...Download