pino icon indicating copy to clipboard operation
pino copied to clipboard

Should formatters and timestamp be done with transport?

Open Saeger opened this issue 4 years ago • 3 comments

Hi,

When reading documentation, it's stated that reformatting should be done using transports for taking the benefit of workerThreads for performance reasons. As stated:

Due to Node's single-threaded event-loop, it's highly recommended that sending, alert triggering, reformatting and all forms of log processing be conducted in a separate process or thread.

So my question from it like: How should we handle simple formats to level and timestamp for example?

Here's a sample code:

this.loggerImpl = pino({
        base: undefined, // Removes the hostname & pid
        timestamp: (): string => {
          return `,"time":"${new Date(Date.now()).toISOString()}"`; // Should it be a transport?
        },
        formatters: {
          // Set level as number
          level: (_label, number): Record<string, any> => {
            return { level: number }; // Should it be a transport?
          },
        },
      }).child({
        name: config.name,
        package: config.package,
        ...{ ...config.labels },
        isUserLog: config.isUserLog,
        offset: this.offset++,
      });

If so, how one should handle such situation here? Additionally, is pino using worker threads underneath by default when doing simple logging?

#1182

Saeger avatar Nov 08 '21 15:11 Saeger

So my question from it like: How should we handle simple formats to level and timestamp for example?

I don't understand the question :(. Can you clarify? Is the doc not covering this well enough? What is missing? the sample code looks ok.

If so, how one should handle such situation here?

What situation?

Additionally, is pino using worker threads underneath by default when doing simple logging?

No it is not, you need to set it up.

mcollina avatar Nov 09 '21 08:11 mcollina

Maybe a little different example than the OP, but for my usage, the replacement of prettyPrint option with the pretty-print as a transport is a problem. I have not yet figured out how I can modify the transport on an instance. What we used to do was be able to set or clear the prettyPrint option to dynamically flip that formatting, for various reasons. Is there a "handle" to the transport, such that I can modify it, enable/disable that transport, or replace by setting a new transport instance on the same logger instance?

thetumper avatar Jul 05 '22 21:07 thetumper

You can just use prettyPrint as a stream: https://github.com/pinojs/pino-pretty#programmatic-integration

mcollina avatar Jul 06 '22 13:07 mcollina

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Mar 20 '23 00:03 github-actions[bot]