-
Notifications
You must be signed in to change notification settings - Fork 941
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
Color not enabled when in a Node Worker #739
Comments
This is an anti-pattern, debug isn't meant to be used like this. I'd say this is a fringe case and Node should fix it on their end, not here. |
The problem is that this may not even be "fixed" in Node. From the referenced issue:
I'd be happy by just manually setting And another super ugly workaround is (in the top of the app): // before loading debug and before creating Workers that also use debug.
const tty = require('tty');
if (tty.isatty(process.stderr.fd)) {
process.env.DEBUG_COLORS = 'true';
} |
Why not just set your main process's environment variable to |
Right now I do NOT need to set So instead of setting |
Not really sure how to fix this elegantly, honestly. You have a very specific use-case where you want threads to include colors but Node is not properly forwarding the correct signals to tell the threads they can safely output escape codes. This isn't something Your "hack" is not a workaround for |
I 100% agree this is a bug in Node, I know that. And I do not even understand their rationale to not forward the
Right. |
I understand their reasoning, I just think it's a weak reason. They created a tight coupling between the environment and their code and they don't seem to want to fix it. However, the blame isn't entirely on them. TTYs are some of the last remaining truly archaic software mechanisms still in prominent use today. I call them "archaic" because they were built in a time of serial lines, baud rates, parallel ports and dialup. The reason why your terminal is called a "terminal emulator" is because they were originally made to emulate old real terminal machines like the VT100. Since then, not much has been done to change this in order to maintain compatibility with old systems running other, equally archaic software. Unix is a huge culprit behind this. It also leaves maintainers of TTY-related software with their hands a bit tied. It also makes output streams a living nightmare to deal with in an elegant and developer-friendly way. Usually, a potential "solution" (such as one proposed above) will cause many others to break. It's the sad state of things, unfortunately :| |
Thanks for the explanation. |
This is related to an ongoing issue/discussion in Node.js related to
process.stdout
andprocess.stderr
not havingisTTY === true
when in a Node.js Worker thread.This means that, if
debug
is used within a Worker thread, it does not print colors nor ms diff (but timestamps).Code to reproduce it (requires Node >= 12 or Node 10 with
node --experimental-worker
flag):foo.js:
Output:
Of course it works if I set
DEBUG_COLORS=true
environment variable. Just wondering if a debug instance may expose a method to set "tty" mode.The text was updated successfully, but these errors were encountered: