Skip to content
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

console.error/warn causes problem with GCP Cloud logging #53665

Closed
Triskae opened this issue Jul 1, 2024 · 5 comments
Closed

console.error/warn causes problem with GCP Cloud logging #53665

Triskae opened this issue Jul 1, 2024 · 5 comments
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs.

Comments

@Triskae
Copy link

Triskae commented Jul 1, 2024

Version

20.15.0

Platform

Linux redacted 6.1.85+ #1 SMP PREEMPT_DYNAMIC Sat May  4 14:32:43 UTC 2024 x86_64 Linux

Subsystem

No response

What steps will reproduce the bug?

use console.error with a nodejs program running and logging to GCP Cloud Logging

How often does it reproduce? Is there a required condition?

Use console.error and it will break the log format.

What is the expected behavior? Why is that the expected behavior?

The expected behaviour is that nothing is added to the string being printed. Since Cloud Logging needs a valid JSON, the following log is outputed:

"[33m{ "severity": "WARNING", "timestamp": "2024-07-01T07:02:00.349Z", "context": "Main.bootstrap", "message": "API service started" }[39m"

this is NOT a valid JSON.

What do you see instead?

"[33m{ "severity": "WARNING", "timestamp": "2024-07-01T07:02:00.349Z", "context": "Main.bootstrap", "message": "API service started" }[39m"

instead of

"{ "severity": "WARNING", "timestamp": "2024-07-01T07:02:00.349Z", "context": "Main.bootstrap", "message": "API service started" }"

Additional information

Linked to this issue: 53661
And this PR: 51629

@RedYetiDev RedYetiDev added console Issues and PRs related to the console subsystem. duplicate Issues and PRs that are duplicates of other issues or PRs. and removed console Issues and PRs related to the console subsystem. labels Jul 1, 2024
@RedYetiDev
Copy link
Member

RedYetiDev commented Jul 1, 2024

Duplicate of #53661


This is the same issue, but in a different context.

@RedYetiDev RedYetiDev marked this as a duplicate of #53661 Jul 1, 2024
@RedYetiDev RedYetiDev closed this as not planned Won't fix, can't repro, duplicate, stale Jul 1, 2024
@RedYetiDev
Copy link
Member

Shouldn't the color only be default when the stdout/stderr are TTY? I wonder #53665 is more of a bug of the TTY detection not smart enough

Linking this message from @joyeecheung, @Triskae do you have any comment on the TTY detection? If so, I apologize for prematurely closing this issue, as it seems like a duplicate

@Triskae
Copy link
Author

Triskae commented Jul 2, 2024

TTY detection ? I'm sorry I don't have knowledge about this ?
The only thing I know is that the console.error add characters to our json string, so it's no more a json string and Cloud Logging is no more able to parse the said json ...

I don't know if it as something to do with TTY

Using console.log, solves the issue, since log doesn't seem to add anything to the printed string

@RedYetiDev
Copy link
Member

Got it! Thanks. See the linked issue for the discussion on coloring.

@joyeecheung
Copy link
Member

joyeecheung commented Jul 2, 2024

The colorization should only happen if your stderr is directed to a terminal. For cloud logging I imagine they would locally pipe the stderr somewhere else (a file or a socket or a pipe) to send the logs over to the server for the users to see in their console (e.g. the browser), in that case the stderr won’t be colorized. Unless GCP tricks Node.js into thinking the stderr is a (pseudo) TTY.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs.
3 participants