Permalink
Browse files

Change all the emitted log events to be in the following format emit(…

…log, level,

message, obj) where obj is an optional object with arguments.
  • Loading branch information...
Kami committed Feb 13, 2012
1 parent 1b12e4f commit 6966cf8c2a69117379a01ac8d1de4b2035e2cead
Showing with 18 additions and 13 deletions.
  1. +18 −13 lib/driver.js
View
@@ -210,20 +210,23 @@ Connection.prototype.connect = function(callback) {
var self = this,
timeoutId;
self.emit('log', 'info', 'connecting ' + self.connectionInfo.host + ':' + self.connectionInfo.port + '(' + this._id + ')');
self.emit('log', 'info', 'connecting ' + self.connectionInfo.host + ':' + self.connectionInfo.port + '(' + this._id + ')',
{'connectionInfo': self.connectionInfo});
// build connection here, so that timeouts on bad hosts happen now and not in the constructor.
this.con = thrift.createConnection(self.connectionInfo.host, self.connectionInfo.port);
this.con.on('error', function(err) {
clearTimeout(timeoutId);
self.emit('log', 'error', self.connectionInfo.host + ':' + self.connectionInfo.port + ' error during connect.');
self.emit('log', 'error', self.connectionInfo.host + ':' + self.connectionInfo.port + ' error during connect.',
{'connectionInfo': self.connectionInfo, 'err': err});
amendError(err, self.connectionInfo);
callback(err);
});
this.con.on('close', function() {
clearTimeout(timeoutId);
self.emit('log', 'info', self.connectionInfo.host + ':' + self.connectionInfo.port + ' is closed (' + self._id + ')');
self.emit('log', 'info', self.connectionInfo.host + ':' + self.connectionInfo.port + ' is closed (' + self._id + ')',
{'connectionInfo': self.connectionInfo});
});
this.con.on('connect', function() {
@@ -390,11 +393,11 @@ Connection.prototype.execute = function(query, args, callback) {
start, end, diff;
start = new Date().getTime();
self.emit('log', 'cql', {'query': query, 'parameterized_query': cqlString, 'args': args});
self.emit('log', 'cql', cqlString, {'query': query, 'parameterized_query': cqlString, 'args': args});
// if a connection dies at the right place, execute_cql_query never returns. make sure the callback gets called.
var longQueryWatch = setTimeout(function() {
self.emit('log', 'trace', "query is taking long: " + cql);
self.emit('log', 'trace', 'query is taking long: ' + cql, {'query': cql, 'timeout': 10000});
},10000);
var timeoutId = setTimeout(function() {
callback(new Error('Connection timed out'));
@@ -403,7 +406,7 @@ Connection.prototype.execute = function(query, args, callback) {
self.client.execute_cql_query(cql, ttypes.Compression.NONE, function(err, res) {
clearTimeout(longQueryWatch);
if (!timeoutId) {
self.emit('log', 'warn', 'query returned after timeout: ' + cql);
self.emit('log', 'warn', 'query returned after timeout: ' + cql, {'query': cql, 'timeout': 10000});
return;
} else {
clearTimeout(timeoutId);
@@ -412,7 +415,7 @@ Connection.prototype.execute = function(query, args, callback) {
end = new Date().getTime();
diff = (end - start);
if (self.connectionInfo.log_time) {
self.emit('log', 'timing', {
self.emit('log', 'timing', cqlString, {
'query': query,
'parameterized_query': cqlString,
'args': args,
@@ -479,11 +482,11 @@ ConnectionInPool.prototype.connect = function(callback) {
// it occupies a fair amount of resources. the callback doesn't need to depend on this since the new transport
// can be repointed before the old transport goes away.
if (self._id !== undefined && self.con && self.client) {
self.emit('log', 'debug', 'initiating proactive transport close');
self.emit('log', 'debug', 'initiating proactive transport close', {});
// ghetto close.
var _con = self.con;
_con.on('close', function(err) {
self.emit('log', 'debug', 'proactive transport close finished');
self.emit('log', 'debug', 'proactive transport close finished', {});
});
_con.end();
}
@@ -566,8 +569,8 @@ var PooledConnection = module.exports.PooledConnection = function(config) {
timeout: self.timeout,
log_time: self.log_time
});
connection.on('log', function(level, message) {
self.emit('log', level, message);
connection.on('log', function(level, message, obj) {
self.emit('log', level, message, obj);
});
this.connections.push(connection);
}
@@ -673,7 +676,8 @@ PooledConnection.prototype.execute = function(query, args, executeCallback) {
} else {
con.unhealthyAt = new Date().getTime();
con.taken = false;
self.emit('log', 'warn', 'setting unhealthy from execute ' + con.connectionInfo.host + ':' + con.connectionInfo.port + ',' + err.message);
self.emit('log', 'warn', 'setting unhealthy from execute ' + con.connectionInfo.host + ':' + con.connectionInfo.port + ',' + err.message,
{'connectionInfo': con.connectionInfo});
// try again.
PooledConnection.prototype.execute.call(self, query, args, callback);
}
@@ -685,7 +689,8 @@ PooledConnection.prototype.execute = function(query, args, executeCallback) {
// individual connection has failed.
con.unhealthyAt = new Date().getTime();
con.taken = false;
self.emit('log', 'warn', 'setting unhealthy from catch outside execute ' + con.connectionInfo.host + ':' + con.connectionInfo.port);
self.emit('log', 'warn', 'setting unhealthy from catch outside execute ' + con.connectionInfo.host + ':' + con.connectionInfo.port,
{'connectionInfo': con.connectionInfo});
// try again.
PooledConnection.prototype.execute.call(self, query, args, callback);
}

0 comments on commit 6966cf8

Please sign in to comment.