Skip to content

Commit

Permalink
Added an argument to set() to establish a quiet mode to suppress cons…
Browse files Browse the repository at this point in the history
…ole logging.
  • Loading branch information
Blane Dabney committed Sep 14, 2011
1 parent 2e39492 commit b587687
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ SysLogger.prototype._sendUDP = function(message, severity, tag) {
client.send(message, 0, message.length, this.port, this.sysloghost,
function(err) {
if (err) {
console.error('Can\'t connect to '+this.sysloghost+':'+this.port + ':' + err);
if(!self.quiet) console.error('Can\'t connect to '+this.sysloghost+':'+this.port + ':' + err);
self.emit("error", 'Can\'t connect to '+this.sysloghost+':'+this.port + ':' + err);
}
});
Expand All @@ -131,7 +131,7 @@ SysLogger.prototype._setupTCP = function(done) {
var self = this;
this._tcpConnection = net.createConnection(this.port, this.sysloghost)
.on("error", function(exception) {
console.log("tcp connect error : " + exception);
if(!self.quiet) console.log("tcp connect error : " + exception);
self.emit("error", exception);
})
.on("close", function(had_error) {
Expand Down Expand Up @@ -163,7 +163,7 @@ SysLogger.prototype._sendTCP = function(message, severity, tag, done) {
this._tcpConnection.write(msg, undefined,
function(err) {
if (err) {
console.log('Can\'t connect to '+this.sysloghost+':'+this.port + ':' + err);
if(!self.quiet) console.log('Can\'t connect to '+this.sysloghost+':'+this.port + ':' + err);
self.emit("error", 'Can\'t connect to '+this.sysloghost+':'+this.port + ':' + err);
}
if(done !== undefined) done(err);
Expand All @@ -179,10 +179,11 @@ SysLogger.prototype._sendTCP = function(message, severity, tag, done) {
* @param {String} Syslog server and optional port number, default is "localhost:514"
* @param {String} protocol to use for syslog communication, can be "tcp" or "udp". Default is "tcp"
*/
SysLogger.prototype.set = function(tag, facility, hostname, sysloghost, protocol) {
SysLogger.prototype.set = function(tag, facility, hostname, sysloghost, protocol, quiet) {
this.setTag(tag);
this.setFacility(facility);
this.setHostname(hostname);
this.setQuiet(quiet);
if(sysloghost === undefined) sysloghost="localhost";
loghost_and_port = sysloghost.split(':');
this.setSyslogHost(loghost_and_port[0]);
Expand Down Expand Up @@ -226,6 +227,10 @@ SysLogger.prototype.setSyslogHost = function(sysloghost) {
this.sysloghost = sysloghost || "localhost";
return this;
}
SysLoggr.prototype.setQuier = function(quiet) {
this.quiet = quiet || false;
return this;
}
/**
* Get new instance of SysLogger. All arguments is similar as `set`
* @returns {SysLogger}
Expand Down Expand Up @@ -307,4 +312,4 @@ SysLogger.prototype.assert = function(expression) {

var logger = new SysLogger();
logger.set();
module.exports = logger;
module.exports = logger;

0 comments on commit b587687

Please sign in to comment.