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

fix: parse structured logs, and handle ANSI escape codes in logs #620

Merged
merged 4 commits into from
Jul 9, 2024

Conversation

jrmfg
Copy link
Contributor

@jrmfg jrmfg commented Jul 8, 2024

firebase-functions/logger writes structured logs to stdout and stderr by default, and makes these pretty with ANSI color codes.

When functions-framework intercepts these messages to assign execution IDs, it handles them incorrectly in two ways.

First, when the log emitted on stdout or stderr is already a structured log, we override (ignore) the severity set by the logger. This commit avoids changing severity if it's already set.

Second, when parsing the message and attempting to determine if it's already a json object/structured log, it doesn't handle ANSI escape codes (https://en.wikipedia.org/wiki/ANSI_escape_code) used to control color, so parsing these will fail. This means that severity handling falls back to just looking at whether the message came from stdout or stderr, so debug-level and warn-level logs aren't handled correctly. This commit strips all ANSI escape codes that control terminal color. This is a minor bummer because it's a whole lot less pretty, but color-coding and smarter color coding generally seems less important than correct log-level handling.

Fixes #617.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Functions Framework v3.4.0 breaks logging in Firebase projects
3 participants