Server side request logging with nuxt.js

March 17, 2020

By default, nuxt.js does not have server-side request logging out of the box. Thankfully, we can quickly add it using the connect-logger with the following additions.

Install the connect-logger package

$ yarn add connect-logger

Update ‘serverMiddleware’ in your nuxt.config.js

import logger from "connect-logger";

  serverMiddleware: [
    logger({ format: "%date %status %method %url (%time)" })
  ],

View the requests in stdout

app_1  | 20.03.17 18:26:56 302 GET /healthy (513ms)
app_1  | 20.03.17 18:27:04 302 GET / (114ms)
app_1  | 20.03.17 18:27:05 302 GET / (38ms)
app_1  | 20.03.17 18:27:16 302 GET /workspaces/1234 (42ms)

Return home