Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Nuxt plugin for the Winston logger. Includes setup for logging in the browser console. Written in TypeScript
import { Plugin } from '@nuxt/types';
import logger from 'logger';
const eventLogger: Plugin = (context, inject) => {
// Inject $logger in Vue, context and store.
inject('logger', logger);
// For Nuxt <= 2.12, also add 👇
context.$logger = logger;
};
export default eventLogger;
import * as winston from 'winston';
import BrowserConsole from 'winston-transport-browserconsole';
const logger = winston.createLogger({
level: 'info',
transports: [
new BrowserConsole(
{
format: winston.format.simple(),
},
),
],
});
// If we're not in production then log to the `console` with the format:
// `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
//
// if (process.env.NODE_ENV !== 'production') {
// logger.add(new winston.transports.Console({
// format: winston.format.simple(),
// }));
// }
export default logger;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.