nuxt-log4nuxt
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

nuxt-log4nuxt

npm version npm downloads License Nuxt

Introduction

A small but helpful logging module for nuxt 3 projects based on nuxt-logger created by mahnuh

Setup

Quick Setup

  1. Add nuxt-log4nuxt dependency to your project
# Using pnpm
pnpm add -D nuxt-log4nuxt

# Using yarn
yarn add --dev nuxt-log4nuxt

# Using npm
npm install --save-dev nuxt-log4nuxt
  1. Add nuxt-log4nuxt to the modules section of nuxt.config.ts
export default defineNuxtConfig({
  modules: [
    'nuxt-log4nuxt'
  ],

  // OPTIONAL CONFIGURATION
  log4nuxt: {
    isEnabled: true, // true or false, defaults to true
    logLevel: 'trace', // trace, debug, info, warn or error, defaults to debug
  }
})

That's it! You can now use log4nuxt in your Nuxt app

Usage

There are 5 methods available, one for each log level (trace, debug, info, warn, error) which accept one or more arguments of any kind.

For example

  this.$log4nuxt.trace('log a trace message')
  this.$log4nuxt.debug('log a debug message')
  this.$log4nuxt.info('log an info message')
  this.$log4nuxt.warn('log a warn message')
  this.$log4nuxt.error('log an error message')

Some more advanced examples of accessing the module methods are given below:

import { useNuxtApp } from '#app'
import { defineComponent } from '@vue/composition-api'

export default defineComponent({
  setup() {
    useNuxtApp().$log4nuxt.debug('logging on setup')
  },
  data() {
    this.$log4nuxt.debug('logging from the data method')
    return {
      hello: "Hello World!"
    }
  },
  mounted() {
    console.log("logging without log4nuxt")
    this.$log4nuxt.debug('logging from mounted')
    this.callLogger(this.$log4nuxt)
  },
  methods: {
    callLogger(logger : any) {
      logger.trace('logging trace from a method')
      logger.debug('logging debug from a method')
      logger.info('logging info from a method')
      logger.warn('logging warn from a method')
      logger.error('logging error from a method')
    }
  }
})

Client Side


Server Side

Changelog

 Release Notes

Contributing

SUBMIT BUGS OR FEATURE REQUESTS

CONTRIBUTING STEPS

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.3
    2
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.3
    2
  • 1.0.2
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i nuxt-log4nuxt

Weekly Downloads

2

Version

1.0.3

License

MIT

Unpacked Size

10.5 kB

Total Files

10

Last publish

Collaborators

  • craftinggamertom