diff --git a/README.md b/README.md index 0c0e284..66b530b 100644 --- a/README.md +++ b/README.md @@ -408,6 +408,17 @@ var log = new EventLogger({ }); ``` +Warning event logs that are produced by the wrapper can be suppressed by disabling it when creating the service. +Warning logs are enabled by default. + +```js +var svc = new Service({ + name:'Hello World', + description: 'The nodejs.org example web server.', + disableWarningLogs: true, +}); +``` + --- # Commands diff --git a/lib/daemon.js b/lib/daemon.js index e4f90b8..302d1b6 100644 --- a/lib/daemon.js +++ b/lib/daemon.js @@ -106,7 +106,8 @@ var daemon = function (config) { '--wait', this.wait, '--maxrestarts', this.maxRestarts, '--abortonerror', (this.abortOnError == true ? 'y' : 'n'), - '--stopparentfirst', this.stopparentfirst + '--stopparentfirst', this.stopparentfirst, + '--disablewarninglogs', (this.disableWarningLogs==true?'y':'n'), ]; if (this.maxRetries !== null) { @@ -132,7 +133,8 @@ var daemon = function (config) { logmode: this.logmode, logging: config.logging, allowServiceLogon: config.allowServiceLogon, - dependsOn: this.dependsOn + dependsOn: this.dependsOn, + disableWarningLogs: this.disableWarningLogs }); } }, @@ -465,6 +467,18 @@ var daemon = function (config) { value: config.execPath !== undefined ? require('path').resolve(config.execPath) : null }, + /** + * @cfg {Boolean} [disableWarningLogs=false] + * Setting this to `true` will prevent warning logs from being sent to the event log. + * This is useful if you want to suppress warnings to clear up the event logs. + */ + disableWarningLogs: { + enumerable: true, + writable: false, + configurable: false, + value: typeof(config.disableWarningLogs) == 'boolean' ? config.disableWarningLogs : false + }, + /** * @property {Array} [dependsOn] * List of service names on which this service will be dependant on diff --git a/lib/eventlog.js b/lib/eventlog.js index 35486f6..2056585 100644 --- a/lib/eventlog.js +++ b/lib/eventlog.js @@ -182,6 +182,9 @@ var logger = function (config) { writable: true, configurable: false, value: function (message, code, callback) { + if (config.disablewarninglogs === 'y') { + return; + } write(this.eventLog, this.source, 'WARNING', message, code, callback); } }, diff --git a/lib/wrapper.js b/lib/wrapper.js index 1d748af..019958b 100644 --- a/lib/wrapper.js +++ b/lib/wrapper.js @@ -62,8 +62,18 @@ var Logger = require('./eventlog'), .check(function (argv) { return ['y', 'n', 'yes', 'no'].indexOf(argv.a.trim().toLowerCase()) >= 0; }) + .default('disablewarninglogs','no') + .alias('dw','disablewarninglogs') + .describe('disablewarninglogs','Prevent warning logs from being written to the event log.') + .check(function(argv){ + return ['y','n','yes','no'].indexOf(argv.a.trim().toLowerCase()) >= 0; + }) .parse(), - log = new Logger(argv.e == undefined ? argv.l : { source: argv.l, eventlog: argv.e }), + log = new Logger({ + source: argv.l, + ...(argv.e ? {eventlog:argv.e} : {}), + disablewarninglogs: argv.dw, + }), fork = require('child_process').fork, script = p.resolve(argv.f), wait = argv.w * 1000,