So far, I have not thought about any extensive logging tool for my Node.js applications. I knew there were several logging tools available, but I was using only the regular console.log feature in my Node.js application. The reason why I wanted Pino was because of the wide features that it gave me, apart from the regular logging. I explored other similar applications that did the logging and ended up with pino for its simplicity and ease of migration.
I had completed my application already with console.log, and then I thought I would create a schema for logs and maintain it in the database. Then, after reading a few articles, they suggested that having the logs inside the database is not an advisable approach. People say that saving it in a file is better than saving it in the database. But I noticed that different people have different views on that, but I find saving it in a file suitable for my needs.
Features that Pino gives
We have a feature to define the log level, which means I can define where my log is an error or info or warning, etc. Based on the type of log, I can also filter it out. Another interesting feature is that the log can be printed in JSON format, which can later be processed into any form we want. There are also tools available that can read from this log file and show it to us in a desired format.
Troubleshooting becomes easier if we have this type of logging. I can simply do a console.log statement, but having it in a structured format helps in troubleshooting in enterprise applications. Pino package is also type safe, and we can use it in our modern development. The setup of the package was also not a headache. I had to just include the package and add a logger.js file (in my case, it was a .ts file) and have the configuration done in that file.
Pino also has a facility where the logs can either be logged in the console itself or it can be saved in a separate log file. Additionally, if required, we can also save the log in multiple places. The default fields available in the configuration itself are sufficient enough but if we would like to customize the configuration, we can do it.
Another important feature that Pino gives is the ability to filter out sensitive information from logging. If the log data is going to be structured, we can easily eliminate the sensitive data and show only the necessary data.
If you like what I'm doing on Hive, you can vote me as a witness with the links below.
![]() |
![]() |
![]() |