Consolidate logstring generation into private fn

This commit is contained in:
Andrew Stewart 2014-06-17 19:18:12 -07:00
parent e8520e3de2
commit 6fa87fbf7c
1 changed files with 14 additions and 16 deletions

View File

@ -69,14 +69,7 @@ Connection.prototype.toJSON = function() {
//
// Returns the result of the supplied callback function
Connection.prototype.connect = function(callback) {
var msg = "Connecting to '" + this.name + "'";
if (this.port != null) {
msg += " on port " + this.port;
}
msg += ".";
var msg = this._logstring("Connecting to");
Logger.info(msg);
return this.adaptor.connect(callback);
};
@ -87,14 +80,7 @@ Connection.prototype.connect = function(callback) {
//
// Returns nothing
Connection.prototype.disconnect = function(callback) {
var msg = "Disconnecting from '" + this.name + "'";
if (this.port != null) {
msg += " on port " + this.port;
}
msg += ".";
var msg = this._logstring("Disconnecting from");
Logger.info(msg);
return this.adaptor.disconnect(callback);
};
@ -125,3 +111,15 @@ Connection.prototype.halt = function(callback) {
Logger.info(msg);
return this.disconnect(callback);
};
Connection.prototype._logstring = function _logstring(action) {
var msg = action + " '" + this.name + "'";
if (this.port != null) {
msg += " on port " + this.port;
}
msg += ".";
return msg;
};