fastify / one-line-logger

Helps you format fastify's log into a nice one line message
MIT License
32 stars 7 forks source link

Add request id in the log? #5

Closed wtchangdm closed 1 year ago

wtchangdm commented 1 year ago

Prerequisites

🚀 Feature Proposal

Hi, I am developing some sort of proxy for internal use. This logger is a good fit for users who want to try on their local environment for better readability.

However, the default format doesn't append request id, which could make user slightly harder to identify the request.

Motivation

Showing request id can be useful to identify what's happening during a specific request. However, when request id is rather long (e.g., front-end proxy sent a request-id header), it can be noisy.

Please let me know what do you think!

Example

Instead of:

YYYY-MM-dd HH:mm:ss.SSSTZ - <level> - <method> <route path> - <message>

Maybe we could use:

YYYY-MM-dd HH:mm:ss.SSSTZ - <level> - <req id> - <method> <route path> - <message>
mcollina commented 1 year ago

This logger is configuration of pino-pretty, check out the source code: https://github.com/fastify/one-line-logger/blob/master/src/index.js.

If you want to customize this, it's easy to fork and adapt to your needs.

wtchangdm commented 1 year ago

Sure, thanks @mcollina