workers-sdk
workers-sdk copied to clipboard
🚀 Feature Request: forward `console.log()` messages from Worker in `unstable_dev()` to an in-memory store
Describe the solution
Currently, when running unstable_dev() any console.log() messages in the Worker itself get forwarded to the console running the unstable_dev() process. This can make test output messy and verbose, hiding the underlying signal of test result. If we had the option of sending these messages to some in-memory array of strings, then we would have cleaner output, but also the ability to test these outputs, similar to how mockConsoleMethods() works in Wrangler tests.
I wonder if unstable_dev returning a stream of log events or something like that would be useful here? And then it could be the caller's responsibility to put that into a buffer if needed. This would be nice in the interests of not letting very chatty Workers exert memory pressure by storing all logs in memory (admittedly perhaps not an issue with the size of logs considered here). It would also be good for the CLI builder use-case; someone building a CLI based on unstable_dev may want to hook into the log events from unstable_dev and do some transformations on them before logging to the console.
Ah yes - even better. Thanks @penalosa. Exposing the stream rather than forwarding it to the console would be plenty good enough and nicely flexible.