fastify / one-line-logger

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

Include response time in "request completed" log #11

Open IqbalLx opened 1 year ago

IqbalLx commented 1 year ago

Prerequisites

🚀 Feature Proposal

Hi! I think it will be better if the completed request log also included the original response time. Maybe something like this 2017-02-14 20:51:48.000+0800 - info - completed in 0.14731597900390625 seconds - request completed

I've been trying to implement this simple feature by myself, but I am not sure how to write test for this response time? Any recommendations maybe, so that I can open PR for this issue.

Thanks

Motivation

No response

Example

No response

Eomm commented 1 year ago

I've been trying to implement this simple feature by myself, but I am not sure how to write test for this response time? Any recommendations maybe, so that I can open PR for this issue.

You need to use some fake timers for it such as sinon

What about this format instead?

2017-02-14 20:51:48.000+0800 - info - request completed in 147 ms
Uzlopak commented 1 year ago

@TommyDew42 Would this fit to the concept of this logger?

TommyDew42 commented 1 year ago

The initial idea (fastify/fastify#4027) was simple and just to provide a better looking log to developers. I guess it's alright to add the response time if users find it useful? @mcollina

jsumners commented 1 year ago

The timing information is easily adjusted by the user:

Eomm commented 1 year ago

The standard response log has that info already