1
votes

I'm very new to NextJS - I currently have a pretty simple app that serves a handful of pages, and returns a 404 page if the route doesn't exist.

I'd like to get logging for every request, including pages that don't exist and return a 404 page. I'm running the app inside a docker container, or I'd like the logs to be written to stdout but not visible in chrome console out.

What's the best way to implement this?

1
Same, deployed with docker nextjs.org/docs/deployment#docker-image, now need to find a solution for logsAnulal S

1 Answers

1
votes

This use-case sounds like an access-log setup.

The best way would be to setup a reverse proxy like nginx so it can create logs in your docker container.

If you don't want to do that, you can follow these two steps

  1. Setup a custom server that gets the request https://nextjs.org/docs/advanced-features/custom-server
  2. Use something like https://www.npmjs.com/package/next-bunyan to write out your logs

If you would like access from the front-end to be logged as well as they traverse the application - You could use something like a Google analytics account to capture both client and server side events.