1

I'm running a Hapi server and I want to log each incoming request to the server.

I found this: How to log all requests made to a hapi server without using a logging library? where it says using code similar to this:

server.on('response', function (request) {
    console.log(request.info.remoteAddress + ': ' + request.method.toUpperCase() + ' ' + request.url.path + ' --> ' + request.response.statusCode);
});

The problem I'm having with this solution is that it's only valid for requests after the response has occurred, while some requests won't get responded in extreme scenarios(e.g not enough CPU to process request).

Do you know how this can be achieved?

gibson
  • 1,066
  • 2
  • 10
  • 22

2 Answers2

2

Using server.ext() with the onRequest event, you should be able to do what you want

Ernest Jones
  • 564
  • 6
  • 20
0

You can use request.log() or if you just want to see what requests are arriving in you can check your web server logs (assuming you are reverse proxying).

cherrysoft
  • 1,165
  • 8
  • 17