node icon indicating copy to clipboard operation
node copied to clipboard

Not logging errors properly

Open gulfpearl opened this issue 11 months ago • 6 comments

There is a bug in the error logging in @mwni/log. When calling log.error(), the error message appears blank in the console, even though log.info() outputs messages correctly.

the issue comes from how the output function spreads the contents array rather than joining it into a single string.

In the output.js std function, I made the following change to make it work for me:

  • func(${prefix}${date} ${level} [\x1b[${colors[color]}${name}\x1b[0m], ...contents)
  • func(${prefix}${date} ${level} [\x1b[${colors[color]}${name}\x1b[0m] ${contents.join(' ')})

gulfpearl avatar Feb 24 '25 20:02 gulfpearl

Interesting. The array of strings usually gets passed to console.log or console.error. This normally prints everything, and it additionally adds colorized formatting based on types, which is why I decided to not join everything into a string.

What runtime (node/bun/deno) are you using and have you made any changes to the code?

Mwni avatar Feb 24 '25 21:02 Mwni

I'm using node v20.18.3 on ubuntu 22.04.

It makes sense that console.error should work like console.log but it doesn't for me.

I haven't made any other changes.

gulfpearl avatar Feb 24 '25 21:02 gulfpearl

What does node -e "console.error('test', 'one', 2)" print on your system?

Mwni avatar Feb 24 '25 21:02 Mwni

test one 2 with the 2 in yellow

gulfpearl avatar Feb 25 '25 01:02 gulfpearl

Then the problem is not the logging itself but more likely the transit of error messages between forked node processes. I remember there being this issue on some edge cases. Can you tell me which module is emitting errors?

Mwni avatar Feb 25 '25 12:02 Mwni

That makes sense, I will check when I'm at my desk tonight, I also DMed you on X with a development request. Thanks.

gulfpearl avatar Feb 25 '25 19:02 gulfpearl