nuxt-log4nuxt
A Nuxt3 Logging Plugin
776
3
| Install | |
|---|---|
npm install nuxt-log4nuxt |
|
| Latest Version: | 1.0.3 |
| Vue: | 3 |
| License: | MIT |
| Last Updated: | Apr 11, 2023 |
| Links: | GitHub · npm |
Maintainer: craftinggamertom
nuxt-log4nuxt
Introduction
A small but helpful logging module for nuxt 3 projects based on nuxt-logger created by mahnuh
Setup
Quick Setup
- Add
nuxt-log4nuxtdependency 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
- Add
nuxt-log4nuxtto themodulessection ofnuxt.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
Contributing
Related Packages
Version History
| Version | Released | Vue | License |
|---|---|---|---|
| 1.0.3 | ^3.0 | MIT | |
| 1.0.2 | ^3.0 | MIT | |
| 1.0.0 | ^3.0 | MIT |