Tweak to SIGINT patch from @jnordberg for #161
This commit is contained in:
parent
96b9f35019
commit
ecf4b8c6a4
4 changed files with 20 additions and 7 deletions
2
AUTHORS
2
AUTHORS
|
@ -10,3 +10,5 @@ Simon Wade (https://github.com/aexmachina)
|
||||||
https://github.com/glenn-murray-bse
|
https://github.com/glenn-murray-bse
|
||||||
Chakrit Wichian (https://github.com/chakrit)
|
Chakrit Wichian (https://github.com/chakrit)
|
||||||
Patrick Mooney (https://github.com/pfmooney)
|
Patrick Mooney (https://github.com/pfmooney)
|
||||||
|
Johan Nordberg (https://github.com/jnordberg)
|
||||||
|
https://github.com/timborodin
|
||||||
|
|
|
@ -8,6 +8,11 @@ Known issues:
|
||||||
|
|
||||||
## bunyan 1.0.1 (not yet released)
|
## bunyan 1.0.1 (not yet released)
|
||||||
|
|
||||||
|
- [issue #126, #161] Ignore SIGINT (Ctrl+C) when processing stdin. `...| bunyan`
|
||||||
|
should expect the preceding process in the pipeline to handle SIGINT. While
|
||||||
|
it is doing so, `bunyan` should continue to process any remaining output.
|
||||||
|
Thanks @timborodin and @jnordberg!
|
||||||
|
|
||||||
- [issue #160] Stop using ANSI 'grey' in `bunyan` CLI output, because of the
|
- [issue #160] Stop using ANSI 'grey' in `bunyan` CLI output, because of the
|
||||||
problems that causes with Solarized Dark themes (see
|
problems that causes with Solarized Dark themes (see
|
||||||
<https://github.com/altercation/solarized/issues/220>).
|
<https://github.com/altercation/solarized/issues/220>).
|
||||||
|
|
18
bin/bunyan
18
bin/bunyan
|
@ -103,6 +103,7 @@ var stdout = process.stdout;
|
||||||
var readingStdin = false;
|
var readingStdin = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---- support functions
|
//---- support functions
|
||||||
|
|
||||||
function getVersion() {
|
function getVersion() {
|
||||||
|
@ -1052,7 +1053,7 @@ function drainStdoutAndExit(code) {
|
||||||
* @param callback {Function} `function ()`
|
* @param callback {Function} `function ()`
|
||||||
*/
|
*/
|
||||||
function processStdin(opts, stylize, callback) {
|
function processStdin(opts, stylize, callback) {
|
||||||
readingStdin = true
|
readingStdin = true;
|
||||||
var leftover = ''; // Left-over partial line from last chunk.
|
var leftover = ''; // Left-over partial line from last chunk.
|
||||||
var stdin = process.stdin;
|
var stdin = process.stdin;
|
||||||
stdin.resume();
|
stdin.resume();
|
||||||
|
@ -1352,10 +1353,6 @@ function asyncForEach(arr, iterator, callback) {
|
||||||
*/
|
*/
|
||||||
var cleanedUp = false;
|
var cleanedUp = false;
|
||||||
function cleanupAndExit(code, signal) {
|
function cleanupAndExit(code, signal) {
|
||||||
// Do not exit if reading form stdin and we get a SIGINT (ctrl-c)
|
|
||||||
if (readingStdin && signal === 'SIGINT') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Guard one call.
|
// Guard one call.
|
||||||
if (cleanedUp) {
|
if (cleanedUp) {
|
||||||
return;
|
return;
|
||||||
|
@ -1392,7 +1389,16 @@ function cleanupAndExit(code, signal) {
|
||||||
|
|
||||||
//---- mainline
|
//---- mainline
|
||||||
|
|
||||||
process.on('SIGINT', function () { cleanupAndExit(1, 'SIGINT'); });
|
process.on('SIGINT', function () {
|
||||||
|
/**
|
||||||
|
* Ignore SIGINT (Ctrl+C) if processing stdin -- we should process
|
||||||
|
* remaining output from preceding process in the pipeline and
|
||||||
|
* except *it* to close.
|
||||||
|
*/
|
||||||
|
if (!readingStdin) {
|
||||||
|
cleanupAndExit(1, 'SIGINT');
|
||||||
|
}
|
||||||
|
});
|
||||||
process.on('SIGQUIT', function () { cleanupAndExit(1, 'SIGQUIT'); });
|
process.on('SIGQUIT', function () { cleanupAndExit(1, 'SIGQUIT'); });
|
||||||
process.on('SIGTERM', function () { cleanupAndExit(1, 'SIGTERM'); });
|
process.on('SIGTERM', function () { cleanupAndExit(1, 'SIGTERM'); });
|
||||||
process.on('SIGHUP', function () { cleanupAndExit(1, 'SIGHUP'); });
|
process.on('SIGHUP', function () { cleanupAndExit(1, 'SIGHUP'); });
|
||||||
|
|
|
@ -114,7 +114,7 @@ test('extrafield.log with color', function (t) {
|
||||||
'[2012-02-08T22:56:52.856Z] \u001b[36m INFO\u001b[39m: '
|
'[2012-02-08T22:56:52.856Z] \u001b[36m INFO\u001b[39m: '
|
||||||
+ 'myservice/123 '
|
+ 'myservice/123 '
|
||||||
+ 'on example.com: \u001b[36mMy message\u001b[39m'
|
+ 'on example.com: \u001b[36mMy message\u001b[39m'
|
||||||
+ '\u001b[90m (extra=field)\u001b[39m\n\u001b[0m');
|
+ ' (extra=field)\n\u001b[0m');
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue