Skip to content

Commit

Permalink
Merge pull request #376 from jkomoda/ignore-warn-logs
Browse files Browse the repository at this point in the history
Add daemon option to suppress warning logs
  • Loading branch information
coreybutler authored May 20, 2024
2 parents 27779d9 + e0880b3 commit 0696973
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 16 additions & 2 deletions lib/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
});
}
},
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/eventlog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},
Expand Down
12 changes: 11 additions & 1 deletion lib/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0696973

Please sign in to comment.