one-line-logger icon indicating copy to clipboard operation
one-line-logger copied to clipboard

Include response time in "request completed" log

Open IqbalLx opened this issue 2 years ago • 5 comments

Prerequisites

  • [X] I have written a descriptive issue title
  • [X] I have searched existing issues to ensure the feature has not already been requested

🚀 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

IqbalLx avatar Dec 27 '22 00:12 IqbalLx

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

Eomm avatar Dec 27 '22 08:12 Eomm

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

Uzlopak avatar Dec 27 '22 09:12 Uzlopak

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

TommyDew42 avatar Dec 27 '22 10:12 TommyDew42

The timing information is easily adjusted by the user:

  • https://www.fastify.io/docs/latest/Reference/Server/#disablerequestlogging
  • https://www.fastify.io/docs/latest/Reference/Reply/#getresponsetime

jsumners avatar Dec 27 '22 13:12 jsumners

The standard response log has that info already

Eomm avatar Dec 28 '22 15:12 Eomm

Closing due to inactivity and, as others have highlighted, this can already be set.

Fdawgs avatar Nov 13 '24 08:11 Fdawgs