Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #167 from godsflaw/log.syslog

bug fixes for log.syslog's config file loading
  • Loading branch information...
commit 1af13203d7241607866e04bf9d52b038768ed4ff 2 parents 270b3a8 + 9eda7de
@baudehlo authored
Showing with 85 additions and 16 deletions.
  1. +18 −11 plugins/log.syslog.js
  2. +67 −5 tests/plugins/log.syslog.js
View
29 plugins/log.syslog.js
@@ -14,22 +14,29 @@ exports.register = function() {
var nowait = ini.general['log_nowait'] || 0;
var always_ok = ini.general['always_ok'] || false;
- this.always_ok = always_ok;
+ if (always_ok && (always_ok >= 1 || always_ok.toLowerCase() === 'true')) {
+ this.always_ok = always_ok = true;
+ }
- if (pid)
- options |= Syslog.LOG_PID;
+ if (pid && (pid >= 1 || pid.toLowerCase() === 'true')) {
+ options |= Syslog.LOG_PID;
+ }
- if (odelay)
- options |= Syslog.LOG_ODELAY;
+ if (odelay && (odelay >= 1 || odelay.toLowerCase() === 'true')) {
+ options |= Syslog.LOG_ODELAY;
+ }
- if (cons)
- options |= Syslog.LOG_CONS;
+ if (cons && (cons >= 1 || cons.toLowerCase() === 'true')) {
+ options |= Syslog.LOG_CONS;
+ }
- if (ndelay)
- options |= Syslog.LOG_NDELAY;
+ if (ndelay && (ndelay >= 1 || ndelay.toLowerCase() === 'true')) {
+ options |= Syslog.LOG_NDELAY;
+ }
- if (nowait)
- options |= Syslog.LOG_NOWAIT;
+ if (nowait && (nowait >= 1 || nowait.toLowerCase() === 'true')) {
+ options |= Syslog.LOG_NOWAIT;
+ }
switch(facility.toUpperCase()) {
case 'MAIL':
View
72 tests/plugins/log.syslog.js
@@ -33,8 +33,8 @@ function _set_up(callback) {
log_pid : 1,
log_odelay : 1,
log_cons : 0,
- log_ndelay : 0,
- log_nowait : 0,
+ log_ndelay : false,
+ log_nowait : 'random',
always_ok : false
}
};
@@ -113,7 +113,7 @@ exports.log_syslog = {
// local teardown
this.plugin.Syslog.init = this.backup.plugin.Syslog.init;
},
- 'hook returns just next() if configured to do so' : function (test) {
+ 'hook returns just next() by default (missing always_ok)' : function (test) {
var next = function (action) {
test.expect(1);
test.isUndefined(action);
@@ -122,10 +122,55 @@ exports.log_syslog = {
this.plugin.syslog(next, this.logger, this.log);
},
- 'hook returns next(OK) if configured to do so' : function (test) {
+ 'hook returns just next() if always_ok is false' : function (test) {
// local setup
this.backup.configfile = this.configfile;
- this.configfile.general.always_ok = true;
+ this.configfile.general.always_ok = 'false';
+ this.plugin.register();
+
+ var next = function (action) {
+ test.expect(1);
+ test.isUndefined(action);
+ test.done();
+ };
+
+ this.plugin.syslog(next, this.logger, this.log);
+ },
+ 'hook returns next(OK) if always_ok is true' : function (test) {
+ // local setup
+ this.backup.configfile = this.configfile;
+ this.configfile.general.always_ok = 'true';
+ this.plugin.register();
+
+ var next = function (action) {
+ test.expect(1);
+ test.equals(action, constants.ok);
+ test.done();
+ };
+
+ this.plugin.syslog(next, this.logger, this.log);
+
+ // local teardown
+ this.configfile = this.backup.configfile;
+ },
+ 'hook returns just next() if always_ok is 0' : function (test) {
+ // local setup
+ this.backup.configfile = this.configfile;
+ this.configfile.general.always_ok = 0;
+ this.plugin.register();
+
+ var next = function (action) {
+ test.expect(1);
+ test.isUndefined(action);
+ test.done();
+ };
+
+ this.plugin.syslog(next, this.logger, this.log);
+ },
+ 'hook returns next(OK) if always_ok is 1' : function (test) {
+ // local setup
+ this.backup.configfile = this.configfile;
+ this.configfile.general.always_ok = 1;
this.plugin.register();
var next = function (action) {
@@ -139,6 +184,23 @@ exports.log_syslog = {
// local teardown
this.configfile = this.backup.configfile;
},
+ 'hook returns next() if always_ok is random' : function (test) {
+ // local setup
+ this.backup.configfile = this.configfile;
+ this.configfile.general.always_ok = 'random';
+ this.plugin.register();
+
+ var next = function (action) {
+ test.expect(1);
+ test.isUndefined(action);
+ test.done();
+ };
+
+ this.plugin.syslog(next, this.logger, this.log);
+
+ // local teardown
+ this.configfile = this.backup.configfile;
+ },
'syslog hook logs correct thing' : function (test) {
// local setup
var next = stub();
Please sign in to comment.
Something went wrong with that request. Please try again.