Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
as/json: use the logger from tchannel
Browse files Browse the repository at this point in the history
  • Loading branch information
Raynos committed May 7, 2015
1 parent 4076cf3 commit f626b99
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
11 changes: 10 additions & 1 deletion node/as/json.js
Expand Up @@ -39,7 +39,8 @@ function TChannelJSON(options) {

var self = this;

self.logger = options && options.logger || null;
// lazily populated from tchannel
self.logger = null;

var bossMode = options && options.bossMode;
self.bossMode = typeof bossMode === 'boolean' ? bossMode : false;
Expand All @@ -56,6 +57,10 @@ TChannelJSON.prototype.send = function send(

var self = this;

if (!self.logger) {
self.logger = req.logger;
}

assert(typeof endpoint === 'string', 'endpoint must be a string');
assert(typeof req.serviceName === 'string' && req.serviceName !== '',
'req.serviceName must be a string');
Expand Down Expand Up @@ -115,6 +120,10 @@ TChannelJSON.prototype.register = function register(
) {
var self = this;

if (!self.logger) {
self.logger = tchannel.logger;
}

tchannel.register(arg1, endpointHandler);

function endpointHandler(req, res, arg2, arg3) {
Expand Down
10 changes: 10 additions & 0 deletions node/test/as-json.js
Expand Up @@ -152,6 +152,15 @@ allocCluster.test('getting an UnexpectedError frame', {
});
var client = cluster.channels[1];

var _error = client.logger.error;
var messages = [];
client.logger.error = function error(msg) {
messages.push(msg);
if (msg !== 'Got unexpected error in handler') {
_error.apply(this, arguments);
}
};

var opts = {
isOptions: true
};
Expand All @@ -174,6 +183,7 @@ allocCluster.test('getting an UnexpectedError frame', {
assert.equal(err.message, 'Unexpected Error');

assert.equal(resp, undefined);
assert.equal(messages.length, 1);

assert.end();
});
Expand Down

0 comments on commit f626b99

Please sign in to comment.