pino
pino copied to clipboard
Logs missing in debugger console using node --inspect
I want to debug my code using node --inspect or node --inspect-brk, but there is not a zero log in the debugger console.
import pino from 'pino';
const logger = pino();
logger.info('Hello World!');
logger.info('Test');
const error = new Error('TestError');
logger.error(error);
setTimeout(() => {
debugger;
}, 2000);
I tried to write my own transport using node:inspector and inspector.console.log or even a simple console.log. But nothing works.
This would be a fun one to add. Once upon a time we had
https://github.com/pinojs/pino-inspector
But we don't have it anymore because it had little usage.
In the meantime I found out, that the transports are running inside node:worker_threads. I think there is no way to use node:inspector inspector.console inside a worker thread. Maybe there is a solution with inspector.Session, session.connectToMainThread() and session.post('Something.fancy'). It would be much more easier to provide a hook inside the main thread like the logMethod hook but way later where the log object is finalized.
I did this and it got the logs to appear in webstorm's remote debugger which I use to connect to node --inspect. I develop on a remote server, mainly because I don't want to run a ton of microservices locally. Setting up a remote debugger is a big staple in my dev environment.
pino({
...otherOptions,
hooks: {
logMethod(args, method) {
console.log(args)
method.apply(this, args)
},
},
})