diff --git a/AUTHORS b/AUTHORS index 1b28a0d..6c50217 100644 --- a/AUTHORS +++ b/AUTHORS @@ -10,3 +10,5 @@ Simon Wade (https://github.com/aexmachina) https://github.com/glenn-murray-bse Chakrit Wichian (https://github.com/chakrit) Patrick Mooney (https://github.com/pfmooney) +Johan Nordberg (https://github.com/jnordberg) +https://github.com/timborodin diff --git a/CHANGES.md b/CHANGES.md index b96c568..3bda2c9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,11 @@ Known issues: ## 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 problems that causes with Solarized Dark themes (see ). diff --git a/bin/bunyan b/bin/bunyan index 1807b37..0baddb0 100755 --- a/bin/bunyan +++ b/bin/bunyan @@ -103,6 +103,7 @@ var stdout = process.stdout; var readingStdin = false; + //---- support functions function getVersion() { @@ -1052,7 +1053,7 @@ function drainStdoutAndExit(code) { * @param callback {Function} `function ()` */ function processStdin(opts, stylize, callback) { - readingStdin = true + readingStdin = true; var leftover = ''; // Left-over partial line from last chunk. var stdin = process.stdin; stdin.resume(); @@ -1352,10 +1353,6 @@ function asyncForEach(arr, iterator, callback) { */ var cleanedUp = false; 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. if (cleanedUp) { return; @@ -1392,7 +1389,16 @@ function cleanupAndExit(code, signal) { //---- 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('SIGTERM', function () { cleanupAndExit(1, 'SIGTERM'); }); process.on('SIGHUP', function () { cleanupAndExit(1, 'SIGHUP'); }); diff --git a/test/cli.test.js b/test/cli.test.js index 7d83184..8b2010b 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -114,7 +114,7 @@ test('extrafield.log with color', function (t) { '[2012-02-08T22:56:52.856Z] \u001b[36m INFO\u001b[39m: ' + 'myservice/123 ' + 'on example.com: \u001b[36mMy message\u001b[39m' - + '\u001b[90m (extra=field)\u001b[39m\n\u001b[0m'); + + ' (extra=field)\n\u001b[0m'); t.end(); }); });