Skip to content

Commit

Permalink
Fix duplicte packet name in debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Oct 26, 2018
1 parent bd86dfe commit 34bc5d1
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 25 deletions.
1 change: 1 addition & 0 deletions Changes.md
Expand Up @@ -7,6 +7,7 @@ you spot any mistakes.
## HEAD

* Fix `connection.threadId` missing on handshake failure
* Fix duplicte packet name in debug output
* Remove special case for handshake in determine packet code
* Small performance improvement starting command sequence

Expand Down
24 changes: 11 additions & 13 deletions lib/protocol/Protocol.js
Expand Up @@ -444,22 +444,20 @@ Protocol.prototype.destroy = function() {

Protocol.prototype._debugPacket = function(incoming, packet) {
var connection = this._connection;
var headline = incoming
? '<-- '
: '--> ';

if (connection && connection.threadId !== null) {
headline += '(' + connection.threadId + ') ';
}

headline += packet.constructor.name;
var direction = incoming
? '<--'
: '-->';
var packetName = packet.constructor.name;
var threadId = connection && connection.threadId !== null
? ' (' + connection.threadId + ')'
: '';

// check for debug packet restriction
if (Array.isArray(this._config.debug) && this._config.debug.indexOf(packet.constructor.name) === -1) {
if (Array.isArray(this._config.debug) && this._config.debug.indexOf(packetName) === -1) {
return;
}

console.log(headline);
console.log(packet);
console.log('');
var packetPayload = Util.inspect(packet).replace(/^[^{]+/, '');

console.log('%s%s %s %s\n', direction, threadId, packetName, packetPayload);
};
8 changes: 5 additions & 3 deletions test/unit/connection/test-debug-exclude.js
Expand Up @@ -4,6 +4,7 @@ var connection = common.createConnection({
debug : ['OkPacket', 'ComPingPacket'],
port : common.fakeServerPort
});
var util = require('util');

var tid = 0;
var server = common.createFakeServer();
Expand All @@ -13,9 +14,10 @@ server.listen(common.fakeServerPort, function (err) {

var messages = [];

console.log = function (str) {
if (typeof str === 'string' && str.length !== 0) {
messages.push(str);
console.log = function () {
var msg = util.format.apply(this, arguments);
if (String(msg).indexOf('--') !== -1) {
messages.push(msg.split(' {')[0]);
}
};

Expand Down
8 changes: 5 additions & 3 deletions test/unit/connection/test-debug-parser-error.js
@@ -1,6 +1,7 @@
var assert = require('assert');
var common = require('../../common');
var connection = common.createConnection({debug: true, port: common.fakeServerPort});
var util = require('util');

var tid = 0;
var server = common.createFakeServer();
Expand All @@ -10,9 +11,10 @@ server.listen(common.fakeServerPort, function (err) {

var messages = [];

console.log = function (str) {
if (typeof str === 'string' && str.length !== 0) {
messages.push(str);
console.log = function () {
var msg = util.format.apply(this, arguments);
if (String(msg).indexOf('--') !== -1) {
messages.push(msg.split(' {')[0]);
}
};

Expand Down
8 changes: 5 additions & 3 deletions test/unit/connection/test-debug.js
@@ -1,6 +1,7 @@
var assert = require('assert');
var common = require('../../common');
var connection = common.createConnection({debug: true, port: common.fakeServerPort});
var util = require('util');

var tid = 0;
var server = common.createFakeServer();
Expand All @@ -10,9 +11,10 @@ server.listen(common.fakeServerPort, function (err) {

var messages = [];

console.log = function (str) {
if (typeof str === 'string' && str.length !== 0) {
messages.push(str);
console.log = function () {
var msg = util.format.apply(this, arguments);
if (String(msg).indexOf('--') !== -1) {
messages.push(msg.split(' {')[0]);
}
};

Expand Down
8 changes: 5 additions & 3 deletions test/unit/pool/test-debug.js
@@ -1,6 +1,7 @@
var assert = require('assert');
var common = require('../../common');
var pool = common.createPool({debug: true, port: common.fakeServerPort});
var util = require('util');

var tid = 0;
var server = common.createFakeServer();
Expand All @@ -10,9 +11,10 @@ server.listen(common.fakeServerPort, function (err) {

var messages = [];

console.log = function (str) {
if (typeof str === 'string' && str.length !== 0) {
messages.push(str);
console.log = function () {
var msg = util.format.apply(this, arguments);
if (String(msg).indexOf('--') !== -1) {
messages.push(msg.split(' {')[0]);
}
};

Expand Down

0 comments on commit 34bc5d1

Please sign in to comment.