forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
process: add --redirect-warnings command line argument
The --redirect-warnings command line argument allows process warnings to be written to a specified file rather than printed to stderr. Also adds an equivalent NODE_REDIRECT_WARNINGS environment variable. If the specified file cannot be opened or written to for any reason, the argument is ignored and the warning is printed to stderr. If the file already exists, it will be appended to. PR-URL: nodejs#10116 Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Michal Zasso <[email protected]> Reviewed-By: Fedor Indutny <[email protected]>
- Loading branch information
1 parent
7b8fcf8
commit a879dc8
Showing
8 changed files
with
181 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
// Tests the NODE_REDIRECT_WARNINGS environment variable by spawning | ||
// a new child node process that emits a warning into a temporary | ||
// warnings file. Once the process completes, the warning file is | ||
// opened and the contents are validated | ||
|
||
const common = require('../common'); | ||
const fs = require('fs'); | ||
const fork = require('child_process').fork; | ||
const path = require('path'); | ||
const assert = require('assert'); | ||
|
||
common.refreshTmpDir(); | ||
|
||
const warnmod = require.resolve(common.fixturesDir + '/warnings.js'); | ||
const warnpath = path.join(common.tmpDir, 'warnings.txt'); | ||
|
||
fork(warnmod, {env: {NODE_REDIRECT_WARNINGS: warnpath}}) | ||
.on('exit', common.mustCall(() => { | ||
fs.readFile(warnpath, 'utf8', common.mustCall((err, data) => { | ||
assert.ifError(err); | ||
assert(/\(node:\d+\) Warning: a bad practice warning/.test(data)); | ||
})); | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
// Tests the --redirect-warnings command line flag by spawning | ||
// a new child node process that emits a warning into a temporary | ||
// warnings file. Once the process completes, the warning file is | ||
// opened and the contents are validated | ||
|
||
const common = require('../common'); | ||
const fs = require('fs'); | ||
const fork = require('child_process').fork; | ||
const path = require('path'); | ||
const assert = require('assert'); | ||
|
||
common.refreshTmpDir(); | ||
|
||
const warnmod = require.resolve(common.fixturesDir + '/warnings.js'); | ||
const warnpath = path.join(common.tmpDir, 'warnings.txt'); | ||
|
||
fork(warnmod, {execArgv: [`--redirect-warnings=${warnpath}`]}) | ||
.on('exit', common.mustCall(() => { | ||
fs.readFile(warnpath, 'utf8', common.mustCall((err, data) => { | ||
assert.ifError(err); | ||
assert(/\(node:\d+\) Warning: a bad practice warning/.test(data)); | ||
})); | ||
})); |