SHIMODA Piro Hiroshi
null+****@clear*****
Mon Oct 6 16:26:49 JST 2014
SHIMODA "Piro" Hiroshi 2014-10-06 16:26:49 +0900 (Mon, 06 Oct 2014) New Revision: cd7f8b3c09733c84a6bd762b653f2c379127c62a https://github.com/droonga/express-droonga/commit/cd7f8b3c09733c84a6bd762b653f2c379127c62a Message: Use loccer/console.trace to output debug logs Removed files: lib/debug.js Modified files: lib/adapter/http.js lib/droonga-protocol/connection.js lib/droonga-protocol/receiver.js test/test-utils.js Modified: lib/adapter/http.js (+6 -7) =================================================================== --- lib/adapter/http.js 2014-09-29 17:17:46 +0900 (bb88481) +++ lib/adapter/http.js 2014-10-06 16:26:49 +0900 (3faad93) @@ -1,5 +1,3 @@ -var debug = require('../debug'); - var command = require('./command'); var wrapper = require('./wrapper'); var api = require('./api'); @@ -9,9 +7,10 @@ function createRequestResponseHandler(params) { var connection = params.connection; var commandName = params.name; var definition = params.definition; + var logger = definition.logger; return (function(request, response) { - debug('adapter.http.createRequestResponseHandler.handle'); + logger.trace('adapter.http.createRequestResponseHandler.handle'); var timeout = definition.timeout || null; var options = { @@ -19,13 +18,13 @@ function createRequestResponseHandler(params) { timeout: timeout }; var callback = function(error, message) { - debug('adapter.http.createRequestResponseHandler.handle.response'); + logger.trace('adapter.http.createRequestResponseHandler.handle.response'); if (error) { - debug('adapter.http.createRequestResponseHandler.handle.response.error:', error); + logger.trace('adapter.http.createRequestResponseHandler.handle.response.error:', error); var body = message && message.body || null; response.jsonp(error, body); } else { - debug('adapter.http.createRequestResponseHandler.handle.response.success'); + logger.trace('adapter.http.createRequestResponseHandler.handle.response.success'); var body = message.body; if (definition.onResponse) { definition.onResponse(body, response); @@ -72,7 +71,7 @@ function createGenericHandler(params) { var definition = params.definition; return (function(request, response) { - debug('adapter.http.createGenericHandler.handle'); + logger.trace('adapter.http.createGenericHandler.handle'); var options = { dataset: definition.dataset, Deleted: lib/debug.js (+0 -13) 100644 =================================================================== --- lib/debug.js 2014-09-29 17:17:46 +0900 (7986acd) +++ /dev/null @@ -1,13 +0,0 @@ -var util = require('util'); - -var debug; -if (process.env.NODE_DEBUG && /express-droonga/.test(process.env.NODE_DEBUG)) { - debug = function() { - console.error('express-droonga:', - util.format.apply(util, arguments)); - }; -} else { - debug = function() {}; -} - -module.exports = debug; Modified: lib/droonga-protocol/connection.js (+8 -8) Mode: 100644 -> 100755 =================================================================== --- lib/droonga-protocol/connection.js 2014-09-29 17:17:46 +0900 (15b8239) +++ lib/droonga-protocol/connection.js 2014-10-06 16:26:49 +0900 (c1dd0dd) @@ -11,7 +11,6 @@ var EventEmitter = require('events').EventEmitter; var fluent = require('fluent-logger'); var FluentReceiver = require('./receiver').FluentReceiver; var util = require('util'); -var debug = require('../debug'); var DEFAULT_FLUENT_TAG = Connection.DEFAULT_FLUENT_TAG = @@ -107,14 +106,15 @@ Connection.prototype._initReceiver = function() { this._receiver.close(); } - var receiver = new FluentReceiver(this.receivePort); + var receiver = new FluentReceiver(this.receivePort, + { logger: this._logger }); receiver.listen((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); + logger.trace('Connection._initReceiver %d: %d %d:', + this._id, receiver._id, this.receivePort, tag); this._receiver = receiver; this._receiver.on(tag, this._handleMessage.bind(this)); @@ -128,13 +128,13 @@ Connection.prototype._handleMessage = function(envelope) { var inReplyTo = envelope.inReplyTo; if (inReplyTo) { delete this._sendingMessages[inReplyTo]; - debug('Connection._handleMessage.reply %d:', this._id, inReplyTo); + logger.trace('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); + logger.trace('Connection._handleMessage.message %d:', this._id, envelope.type); this.emit(envelope.type, envelope); } }; @@ -186,7 +186,7 @@ Connection.prototype.emitMessage = function(type, body, callback, options) { } var id = createId(); - debug('Connection.emitMessage %d:', this._id, id, type); + logger.trace('Connection.emitMessage %d:', this._id, id, type); var from = this.getRouteToSelf(options); var envelope = { id: id, @@ -202,7 +202,7 @@ Connection.prototype.emitMessage = function(type, body, callback, options) { var event = 'reply:' + id; var timeoutId; this.once(event, function(errorCode, response) { - debug('Connection.emitMessage.reply %d:', this._id, errorCode); + logger.trace('Connection.emitMessage.reply %d:', this._id, errorCode); clearTimeout(timeoutId); callback(errorCode, response); }); Modified: lib/droonga-protocol/receiver.js (+7 -6) =================================================================== --- lib/droonga-protocol/receiver.js 2014-09-29 17:17:46 +0900 (7e56940) +++ lib/droonga-protocol/receiver.js 2014-10-06 16:26:49 +0900 (e2efff4) @@ -1,12 +1,13 @@ -var debug = require('../debug'); var util = require('util'); var net = require('net'); var EventEmitter = require('events').EventEmitter; var msgpack = require('msgpack'); -function MsgPackReceiver(port) { +function MsgPackReceiver(port, options) { EventEmitter.call(this); this.port = port || undefined; + options = options || {}; + this._logger = options.logger || console; this._connections = []; this._init(); } @@ -35,7 +36,7 @@ MsgPackReceiver.prototype._onConnect = function(socket) { }; MsgPackReceiver.prototype._onMessageReceive = function(data) { - debug('MsgPackReceiver._onMessageReceive %d:', this._id); + this._logger.trace('MsgPackReceiver._onMessageReceive %d:', this._id); this.emit('receive', data); }; @@ -75,7 +76,7 @@ exports.MsgPackReceiver = MsgPackReceiver; * Message (used by fluent-logger-node) * [tag, time, data] */ -function FluentReceiver(port) { +function FluentReceiver(port, options) { MsgPackReceiver.apply(this, arguments); } @@ -86,11 +87,11 @@ FluentReceiver.prototype._onMessageReceive = function(packet) { if (packet.length == 3) { // Message type var tag = packet[0]; var response = packet[2]; - debug('FluentReceiver._onMessageReceive.message %d', this._id, tag); + this._logger.trace('FluentReceiver._onMessageReceive.message %d', this._id, tag); this.emit(tag, response); } else { // Forward type - debug('FluentReceiver._onMessageReceive.forward %d', this._id, packet); + this._logger.trace('FluentReceiver._onMessageReceive.forward %d', this._id, packet); packet[1].forEach(function(entry) { this.emit(packet[0], entry[1]); }, this); Modified: test/test-utils.js (+1 -2) =================================================================== --- test/test-utils.js 2014-09-29 17:17:46 +0900 (3d24a0d) +++ test/test-utils.js 2014-10-06 16:26:49 +0900 (6d89faa) @@ -1,4 +1,3 @@ -var debug = require('../lib/debug'); var assert = require('chai').assert; var nodemock = require('nodemock'); var net = require('net'); @@ -260,7 +259,7 @@ function createBackend() { backend.clearMessages(); backend.on('receive', function(data) { - debug('test-utils.createBackend.receive %d', backend._id); + console.trace('test-utils.createBackend.receive %d', backend._id); backend.received.push(data); if (backend.reservedResponses.length > 0) { var response = backend.reservedResponses.shift(); -------------- next part -------------- HTML����������������������������... Download