Your library newspapers

Maximize job database potential with expert discussions and advice.
Post Reply
poxoja9630
Posts: 9
Joined: Sun Dec 22, 2024 5:31 am

Your library newspapers

Post by poxoja9630 »

Before we do that,
  • let's address the fact that the output is not really human-readable at the moment. This is intentional. pino follows a philosophy
that you should, for performance reasons, move all log processing to a separate process by pipe-ing the output (using |). This involves making the output human-readable or uploading it to a cloud host. This is called transports. Also, see the documentation ontransports for more information on why errors in pino are not written to stderr.

Let's use the tool pino-pretty to view a more readable version of the logs. In your terminal, run:

Bash

Copy the code
npm install --save-dev pino-pretty
LOG_LEVEL=debug node index.js | ./node_modules/.bin/pino-pretty
All your logs will now be passed using the | to operator command philippines mobile number example pino-pretty, and your output should be cleaned up to contain only the crucial information in color. If you send a request to http://localhost:3000 again , you should see your message as well debug.

Screenshot of beautifully printed pino newspapers
There are a variety of existing transports to beautify or transform your logs. You can even display them with emojis using pino-colada. These will come in handy when developing locally. Once you're running your server in production, you may want to move your logs to another transport , write them to disk using > for further processing, or do both using a command like tee.

Image

The documentation also includes information on things like rotating log files, filtering, and writing logs to different files.

Your library newspapers
Now that we've seen how to write logs efficiently for our server applications, why not use the same technology for the libraries we create?

The problem is that your library may want to log some things for debugging purposes, but it really shouldn't clutter the user's application. Instead, the user should be able to enable logging if they need to debug something. Your library should be silent by default and leave the choice of writing output to the user.
Post Reply