denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
97.81k stars 5.38k forks source link

Add support to redirect a Worker's `console.log` #20269

Open OoDeLally opened 1 year ago

OoDeLally commented 1 year ago

I need the parent thread to transform whatever the worker logs on the console, e.g.

// parent.ts
console.log("hey there, I'm the parent.");

// worker.ts
console.log("hey there, I'm a child!");

// terminal when running
[LOG] hey there, I'm the parent.
[Worker 42] [LOG] hey there, I'm a child!

I got it working with pipes for child processes. However I cannot see any method to do that with workers. I've also tried to temporarily override console.log into a wrapper in the parent before creating the worker, in vain. Is there a theoretical reason I could not do that, or is it merely a missing feature? Thanks

lucacasonato commented 1 year ago

You can replace console.log in the worker itself. There is no built in feature that enables you to do this? What is your usecase?

OoDeLally commented 1 year ago

The worker code is a third-party source code, and it is run with all permissions turned off. The goal is to prevent the worker to access the raw console, and instead wrap it into a custom logger.