Skip to content

Commit 34bc5d1

Browse files
committed
Fix duplicte packet name in debug output
1 parent bd86dfe commit 34bc5d1

File tree

6 files changed

+32
-25
lines changed

6 files changed

+32
-25
lines changed

Diff for: Changes.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ you spot any mistakes.
77
## HEAD
88

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

Diff for: lib/protocol/Protocol.js

+11-13
Original file line numberDiff line numberDiff line change
@@ -444,22 +444,20 @@ Protocol.prototype.destroy = function() {
444444

445445
Protocol.prototype._debugPacket = function(incoming, packet) {
446446
var connection = this._connection;
447-
var headline = incoming
448-
? '<-- '
449-
: '--> ';
450-
451-
if (connection && connection.threadId !== null) {
452-
headline += '(' + connection.threadId + ') ';
453-
}
454-
455-
headline += packet.constructor.name;
447+
var direction = incoming
448+
? '<--'
449+
: '-->';
450+
var packetName = packet.constructor.name;
451+
var threadId = connection && connection.threadId !== null
452+
? ' (' + connection.threadId + ')'
453+
: '';
456454

457455
// check for debug packet restriction
458-
if (Array.isArray(this._config.debug) && this._config.debug.indexOf(packet.constructor.name) === -1) {
456+
if (Array.isArray(this._config.debug) && this._config.debug.indexOf(packetName) === -1) {
459457
return;
460458
}
461459

462-
console.log(headline);
463-
console.log(packet);
464-
console.log('');
460+
var packetPayload = Util.inspect(packet).replace(/^[^{]+/, '');
461+
462+
console.log('%s%s %s %s\n', direction, threadId, packetName, packetPayload);
465463
};

Diff for: test/unit/connection/test-debug-exclude.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var connection = common.createConnection({
44
debug : ['OkPacket', 'ComPingPacket'],
55
port : common.fakeServerPort
66
});
7+
var util = require('util');
78

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

1415
var messages = [];
1516

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

Diff for: test/unit/connection/test-debug-parser-error.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var assert = require('assert');
22
var common = require('../../common');
33
var connection = common.createConnection({debug: true, port: common.fakeServerPort});
4+
var util = require('util');
45

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

1112
var messages = [];
1213

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

Diff for: test/unit/connection/test-debug.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var assert = require('assert');
22
var common = require('../../common');
33
var connection = common.createConnection({debug: true, port: common.fakeServerPort});
4+
var util = require('util');
45

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

1112
var messages = [];
1213

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

Diff for: test/unit/pool/test-debug.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var assert = require('assert');
22
var common = require('../../common');
33
var pool = common.createPool({debug: true, port: common.fakeServerPort});
4+
var util = require('util');
45

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

1112
var messages = [];
1213

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

0 commit comments

Comments
 (0)