Next.js Discord

Discord Forum

Logging requests in self-hosted deployment

Unanswered
Erythrina gall wasp posted this in #help-forum
Open in Discord
Erythrina gall waspOP
In a self-hosted environment, when building the standalone version, how can I log access logs? When running node server.js, no logs are being outputted. I would like to log access requests to better monitor and debug my Next.js application. Can someone guide me on the proper setup or configuration required for logging access logs in a self-hosted, standalone Next.js deployment?

12 Replies

IDK much about it, but I'll try to help.

How have you deployed it?
Erythrina gall waspOP
Thanks.

I built it in Standalone mode using this Dockerfile ( https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile )

Started it with docker run -p 3000:3000 .
(It's the same when deployed to AWS ECS Fargate)

Requested with curl http://localhost:3000/ etc.
There are no access logs in the console

Even with npm run build && npm run start, access logs are not output. Only startup messages are output to the console:

nextjs-sample@0.1.0 start
next start

   â–² Next.js 14.1.3
   - Local:        http://localhost:3000

 ✓ Ready in 186ms
Erythrina gall waspOP
Ah, and it didn't work even when I wrote export const dynamic = "force-dynamic";. It also didn't work when doing server-side processing with RSC.
Erythrina gall waspOP
I think the logs from node server.js or npm run start are stdout, so they should show up in the host's console.
Erythrina gall waspOP
Even when I checked the logs with docker logs -f [Container ID], I didn't see any access logs other than the startup logs. Additionally, even when not using Docker and starting Next.js directly, no access logs were displayed. The only time they were displayed was when I started it with npm run dev.
try export const dynamic = 'force-dynamic' on the route and add a console.log('rendering') then check the container log
the page is dynamic on dev mode
Erythrina gall waspOP
It should probably be a dynamic site.
I have added export const dynamic = "force-dynamic"; and also used DynamicRoutes in /posts/[id]/page.tsx.