pinojs / pino

🌲 super fast, all natural json logger
http://getpino.io
MIT License
14.4k stars 885 forks source link

Logs missing in debugger console using node --inspect #1983

Open richterdennis opened 6 months ago

richterdennis commented 6 months ago

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.

mcollina commented 6 months ago

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.

richterdennis commented 6 months ago

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.

SimulShift commented 4 weeks ago

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)
          },
        },
        })