Skip to content

Let bunyan EPIPE errors silently fail #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ const loggers = Object.create(null);

const level = bunyan.FATAL + 1;

/**
* As described in this issue on the `bunyan` repo: https://github.com/trentm/node-bunyan/issues/491.
* Under the hood, bunyan connects the logger to process.stdout.
* What happens when starting a service and piping it into bunyan with `yarn service | bunyan`, then hitting `ctrl+C`:
* - `ctrl+C` closes the bunyan process. This results in process.stdout being no longer writable.
* - `ctrl+C` may not immeditely close `service`. For example, if `service` implements `process.on(SIGINT)`, it will perform some extra actions, eventually calling debugnyan's logger.
* Calling debugnyan's logger triggers a write on process.stdout, which at this point results in an `EPIPE error` because the bunyan process is closed.
* The following block ensures that if process.stdout is closed, then trying to log anything will silently fail.
*/
process.stdout.on('error', error => {
if (error.code !== 'EPIPE') {
throw error;
}
});

/**
* Export `debugnyan`.
*/
Expand Down