Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should formatters and timestamp be done with transport? #1213

Closed
Saeger opened this issue Nov 8, 2021 · 4 comments
Closed

Should formatters and timestamp be done with transport? #1213

Saeger opened this issue Nov 8, 2021 · 4 comments

Comments

@Saeger
Copy link

Saeger commented Nov 8, 2021

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

@mcollina
Copy link
Member

mcollina commented Nov 9, 2021

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.

@thetumper
Copy link

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?

@mcollina
Copy link
Member

mcollina commented Jul 6, 2022

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

@github-actions
Copy link

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 github-actions bot locked as resolved and limited conversation to collaborators Mar 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants