Skip to content

Log warnings directly to stderr locally - #1444

Merged
mrbbot merged 1 commit into
mainfrom
bcoll/log-warnings-to-stderr
Nov 28, 2023
Merged

mrbbot merged 1 commit into
mainfrom
bcoll/log-warnings-to-stderr

Conversation

@mrbbot

@mrbbot mrbbot commented Nov 28, 2023

Copy link
Copy Markdown
Contributor

Hey! 👋 With #1294, console.log()s are now logged directly to stdio when running locally. This means Wrangler no longer uses the V8 inspector to receive log messages. Unfortunately, this means we're were missing out on some warnings from workerd. This change logs those warnings directly to stderr too if we're running locally.

Ref: cloudflare/workers-sdk#4512

@mrbbot
mrbbot requested review from a team as code owners November 28, 2023 12:10
@mrbbot
mrbbot requested review from fhanau and ohodson November 28, 2023 12:10
Comment thread src/workerd/io/worker.c++
KJ_LOG(INFO, "console warning", description);
} else {
fprintf(stderr, "%s\n", description.cStr());
fflush(stderr);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stderr is unbuffered, fflush probably isn't helping here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that initially too, but when spawning workerd from Node and piping the output to a stream, it looks like you need explicit flushes. See #1343.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I thought it was buffered too, that's surprising. An alternative might be to use setvbuf()/setlinebuf() to enable line buffering for stderr, but that would affect it outside of this scope too.

@mrbbot
mrbbot merged commit 37fce2b into main Nov 28, 2023
@mrbbot
mrbbot deleted the bcoll/log-warnings-to-stderr branch November 28, 2023 20:21
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.

4 participants