Closed emmacasolin closed 2 years ago
This changes the default log handler to print out to STDERR instead of STDOUT. This makes sense for most unixy applications.
In browsers and in jest, console.error
is augmented in ways beyond console.log
. Both of these will print it out more "prettier" than normal.
For example:
And jest will highlight any usage of console.error
, and probably show where it is coming from. This can be quite useful to find out any logs that being printed out that aren't connected to the logger hierarchy.
In some ways, this is a breaking change though, so merging this should bump a major version.
In Jest this is what it will look like now:
console.error
2020-01-01T00:00:00.000Z:WARN MESSAGE
3 | class ConsoleHandler extends Handler {
4 | public emit(output: string): void {
> 5 | console.error(output);
| ^
6 | }
7 | }
8 |
at console.<anonymous> (node_modules/jest-mock/build/index.js:854:25)
at ConsoleHandler.emit (src/handlers/ConsoleHandler.ts:5:13)
at ConsoleHandler.handle (src/Handler.ts:18:10)
at Logger.callHandlers (src/Logger.ts:112:15)
Compared to before:
console.log
2020-01-01T00:00:00.000Z:DEBUG MESSAGE
at console.<anonymous> (node_modules/jest-mock/build/index.js:854:25)
Before merging this, you want to check that this won't result in crazy amounts of noise in our downstream projects. I believe it shouldn't because downstream projects should be using StreamHandler
.
Before merging this, you want to check that this won't result in crazy amounts of noise in our downstream projects. I believe it shouldn't because downstream projects should be using
StreamHandler
.
How would I check for this?
Just monkey patch the node_modules/@matrixai/logger
with console.error
or use npm link
.
js-polykey passes all tests after monkey patching the node module to use console.error
. I checked to see what it looks like if we use the default console handler. It's pretty much the same as the console.log
but with some extra trace information.
I think this should be good to merge.
Description
Switching from
console.log
toconsole.error
in order to log to stderr rather than stdout.Tasks
console.log
inConsoleHandler.ts
toconsole.error
error
instead oflog
Final checklist