Tweak to SIGINT patch from @jnordberg for #161

master
Trent Mick 2014-08-24 23:34:38 -07:00
parent 96b9f35019
commit ecf4b8c6a4
4 changed files with 20 additions and 7 deletions

View File

@ -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

View File

@ -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
<https://github.com/altercation/solarized/issues/220>).

View File

@ -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'); });

View File

@ -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();
});
});