Skip to content
Nuxt module for logging SSR errors + client-side Vue errors using winston
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
serverMiddleware
.gitignore
.npmignore
CHANGELOG.md
README.md
icon.png
index.js
package.json
plugin.js
utils.js
yarn.lock

README.md

nuxt-winston-log

Winston + Nuxt logo

A module to add winston / logging to your Nuxt application. This module only supports Nuxt apps running in universal mode.

By default the following events are captured:

  1. error level: SSR errors via Nuxt middleware hooks
  2. error level: Unhandled Vue exceptions from the client, delivered to the backend via a small built-in API
  3. info level: Basic access logs for all endpoints in your Nuxt app

All logs captured include a bit of additional metadata pulled from the Node.js request object:

{
  url: 'https://cool.net',
  method: 'GET',
  headers: {
    'X-Plumbus': "36f7b241-2910-4439-8671-749fc77dc213"
  }
}

Logs are output at ./logs/{NODE_ENV}.log by default. They are created in JSON Lines format.

Installation

  1. Install npm package
$ yarn add nuxt-winston-log # or npm i nuxt-winston-log
  1. Edit your nuxt.config.js file to add module
{
  modules: ['nuxt-winston-log']
}
  1. Change options as needed. See Usage section for details.

Usage

  1. By default, nuxt-winston-log exposes some basic options for common needs. Internally, these options are used to create a basic Logger instance and wire up middleware.

    The default values are:

{
  // Path that log files will be created in.
  // Change this to keep things neat.
  logPath: './logs',
  // Name of log file.
  // Change this to keep things tidy.
  logName: `${process.env.NODE_ENV}.log`,
  // Built-in API path for errors from the client.
  // Change this to avoid collisions with your routes.
  capturePath: '/_capture',
}
  1. To customize the File Transport instance, pass options to the transportOptions key:
import path from 'path'
const logfilePath = path.resolve(process.cwd(), './logs', `${process.env.NODE_ENV}.log`)

export default {
  winstonLog: {
    transportOptions: {
      filename: logfilePath
    }
  }
}
  1. To customize the Logger instance, pass options to the loggerOptions key. Note that you can completely overwrite all defaults this way, and establish your own format, transports, and so on.
import { format, transports } from 'winston'
const { combine, timestamp, label, prettyPrint } = format

export default {
  winstonLog: {
    loggerOptions: {
      format: combine(
        label({ label: 'Custom Nuxt logging!' }),
        timestamp(),
        prettyPrint()
      ),
      transports: [new transports.Console()]
    }
  }
}

Changelog

You can’t perform that action at this time.