Enhancing the default logger configuration
You know the options available in the logger, but what is a valuable configuration, and how can we integrate it into our application? First of all, we need to define which logs we expect for every request:
Figure 11.1 – Request logs logic
As shown in Figure 11.1, we expect these log lines for each request: one for the incoming request, optionally, how many handler’s log messages you implement, and finally, one for the response output. All these log lines will be connected to each other by the reqId (request-id) field. It is a unique identifier generated for each request whenever the server receives it. We already described the
reqId property in Chapter 1 in the The Request component section.
We can start implementing this by doing the following:
- Exploiting the default request and response log implemented by Fastify
- Executing a custom log statement by using the