All Projects → aaronransley → nuxt-winston-log

aaronransley / nuxt-winston-log

Licence: other
Nuxt module for logging SSR errors using winston

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to nuxt-winston-log

nuxt-prune-html
🔌⚡ Nuxt module to prune html before sending it to the browser (it removes elements matching CSS selector(s)), useful for boosting performance showing a different HTML for bots/audits by removing all the scripts with dynamic rendering
Stars: ✭ 69 (+68.29%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-humans-txt
🧑🏻👩🏻 "We are people, not machines" - An initiative to know the creators of a website. Contains the information about humans to the web building - A Nuxt Module to statically integrate and generate a humans.txt author file - Based on the HumansTxt Project.
Stars: ✭ 27 (-34.15%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
vue-plausible
Plausible Analytics Vue.js Plugin and NuxtJS Module
Stars: ✭ 107 (+160.98%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-typo3
TYPO3 Frontend rendered in Vue.js and Nuxt (frontend for EXT:headless)
Stars: ✭ 66 (+60.98%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-stripejs
💳 NuxtJS module for Stripe.js which loads only when required and w/ retry mechanism
Stars: ✭ 17 (-58.54%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-ghost
Easy Ghost content API integration with Nuxt.js.
Stars: ✭ 27 (-34.15%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
lumen-cms
GraphQL API-First CMS based on NodeJS and Vue 2, Nuxt and Vuetify
Stars: ✭ 77 (+87.8%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
global-components
Module to register global components for Nuxt.js
Stars: ✭ 57 (+39.02%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-speedkit
nuxt-speedkit will help you to improve the lighthouse performance score (100/100) of your website.
Stars: ✭ 401 (+878.05%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
applicationinsights-module
Application Insights module for NuxtJS
Stars: ✭ 14 (-65.85%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-jsonld
A Nuxt.js module to manage JSON-LD in Vue component.
Stars: ✭ 198 (+382.93%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-stencil
Easy Stencil.js component library integration with Nuxt.js.
Stars: ✭ 16 (-60.98%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-gsap-module
GSAP module for Nuxt.js
Stars: ✭ 183 (+346.34%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-modules
AX2's Nuxt modules
Stars: ✭ 30 (-26.83%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
k-domains
A simple module to manage multiple subdomains with just one project
Stars: ✭ 41 (+0%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-ts-module
A tiny module to use Typescript within Nuxt.js application.
Stars: ✭ 21 (-48.78%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-babel
Use normal .babelrc file with your Nuxt app
Stars: ✭ 32 (-21.95%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-feature-toggle
The nuxt feature toggle module
Stars: ✭ 78 (+90.24%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
nuxt-quasar
Nuxt module for the Quasar Framework
Stars: ✭ 36 (-12.2%)
Mutual labels:  nuxt, nuxtjs, nuxt-module
supabase
An easy way to integrate Supabase with NuxtJS
Stars: ✭ 39 (-4.88%)
Mutual labels:  nuxt, nuxtjs, nuxt-module

nuxt-winston-log

A Nuxt 2.x module to add winston-powered logging to your Nuxt application.

  • Works with: Nuxt @2.x projects running on a server (e.g. universal, SSR mode).
  • Does not support: Statically generated Nuxt projects (i.e. SSG via nuxt generate).

Winston + Nuxt logo

Introduction

By default the following events are captured:

  1. error level: SSR errors via Nuxt middleware hooks
  2. info level: Basic access logs for serverMiddleware endpoints + pages 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 using the winstonLog key 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`,
    
      // Setting to determine if filesystem is accessed to auto-create logPath.
      // Set this to `false` for non-filesystem based logging setups.
      autoCreateLogPath: true,
    
      // Setting to determine if default logger instance is created for you.
      // Set this to `false` and provide `loggerOptions` (usage item #3) to
      // completely customize the logger instance (formatting, transports, etc.)
      useDefaultLogger: true,
    
      // Settings to determine if default handlers should be
      // registered for requests and errors respectively.
      // Set to `true` to skip request logging (level: info).
      skipRequestMiddlewareHandler: false,
      // Set to `true` to skip error logging (level: error).
      skipErrorMiddlewareHandler: false
    }
    // ...
  2. To customize the File Transport instance, pass options to the transportOptions key:

    Example in your apps ~/nuxt.config.js file:

    import path from 'path'
    const logfilePath = path.resolve(process.cwd(), './logs', `${process.env.NODE_ENV}.log`)
    
    export default {
      // Configure nuxt-winston-log module
      winstonLog: {
        transportOptions: {
          filename: logfilePath
        }
      }
    }
  3. To customize the Logger instance, set useDefaultLogger option to false, and make sure you provide a custom set of loggerOptions to be passed to Winston's createLogger under the hood:

    Example in your apps ~/nuxt.config.js file:

    // Note imports from winston core for transports, formatting helpers, etc.
    import { format, transports } from 'winston'
    const { combine, timestamp, label, prettyPrint } = format
    
    export default {
      // Configure nuxt-winston-log module
      winstonLog: {
        useDefaultLogger: false,
        loggerOptions: {
          format: combine(
            label({ label: 'Custom Nuxt logging!' }),
            timestamp(),
            prettyPrint()
          ),
          transports: [new transports.Console()]
        }
      }
    }
  4. To disable automatic creation of the logPath directory, set autoCreateLogPath option to false:

    Example in your apps ~/nuxt.config.js file:

    // ...
    export default {
      // Configure nuxt-winston-log module
      winstonLog: {
        autoCreateLogPath: false
      }
    }
    // ...
  5. To access the winston logger instance from within Nuxt lifecycle areas, use the $winstonLog key from the Nuxt context object. Note: This is only available for server-side executions. For example, because asyncData is an isomorphic function in Nuxt, you will need to guard $winstonLog access with something like if (process.server) { ... }

    Example nuxtServerInit in your apps ~/store/index.js:

    // ...
    export const actions = {
      async nuxtServerInit({ store, commit }, { req, $winstonLog }) {
        $winstonLog.info(`x-forwarded-host: ${req.headers['x-forwarded-host']}`)
      }
    }
    // ...

    Example asyncData in your apps ~/pages/somepage.vue:

    // ...
    asyncData(context) {
      if (process.server) {
        context.$winstonLog.info('Hello from asyncData on server')
      }
    }
    // ...
  6. To disable default request and error logging behaviors, the skipRequestMiddlewareHandler and skipErrorMiddlewareHandler options can be set to true. For more information on what these handlers do out of the box, see the source at the bottom of the ~/index.js file.

    Example in your apps ~/nuxt.config.js file:

    // ...
    export default {
      // Configure nuxt-winston-log module
      winstonLog: {
        skipRequestMiddlewareHandler: true,
        skipErrorMiddlewareHandler: true
      }
    }
    // ...

    Adding your own middleware handlers to Nuxt is outside the scope of this documentation, but can be accomplished using a custom module of your own.

Using process.winstonLog in a Nuxt Module

Because modules are executed sequentially, any additional Nuxt modules should be loaded after the nuxt-winston-log module. You can then access the logger instance via process.winstonLog as needed.

Changelog

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].