audreyt / node-webworker-threads

Lightweight Web Worker API implementation with native threads
https://npmjs.org/package/webworker-threads
Other
2.3k stars 149 forks source link

Cannot override console.log #166

Closed ncthbrt closed 7 years ago

ncthbrt commented 7 years ago

Hi there,

I'm writing an application which needs to run code provided by users. The previous iteration was using VM2. To allow the users to debug what is going on in the backend, the previous iteration overrode console.log and funneled that to the frontend.

However I do not seem to be able to do this in webworker-threads.

Minimally reproducible case:

const Worker = require('webworker-threads').Worker;

let worker = new Worker(()=>{
   let log = console.log;
   console.log = (msg) => log('Hello '+msg);
   self.onmessage = (evt) => console.log(evt.data);
});

worker.postMessage('Nick');

Expected output: Hello Nick

Actual output: Nick

I'm running the latest LTS version of node (I belive it's v6.11.2)