pino-http icon indicating copy to clipboard operation
pino-http copied to clipboard

Log at the beginning of the request

Open muuhoffman opened this issue 3 years ago • 1 comments

For human readable logs I think it makes sense to have a log at the beginning of the request and at the end so it's easy to see in the logs what happens between the start and end of the request. Right now I'm accomplishing it by doing this:

  server.use((req, res, next) => {
    // log the start of the request
    logger.info({msg: "Handling request", "url": req.url})
    return expressLogger(req, res, next);    
  });

However, this method doesn't exclude routes from my ignorePaths, so it seems like this would be pretty nice to just have a function or something in the configuration that gets run before the rest of the request code gets executed that can print out something before the request runs. This took me a lot of trial and error to find the right placement here. I'm curious if other people have this need, and if this is the best practice for accomplishing this today.

muuhoffman avatar Jan 29 '21 17:01 muuhoffman

There is customReceivedMessage that was added in #177

https://github.com/pinojs/pino-http#pinohttpopts-stream

francisdb avatar Feb 27 '22 21:02 francisdb