Skip to content

Instantly share code, notes, and snippets.

@james2doyle
Created October 6, 2020 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save james2doyle/18f3a19d7b18ddc7688510b0c10c6658 to your computer and use it in GitHub Desktop.
Save james2doyle/18f3a19d7b18ddc7688510b0c10c6658 to your computer and use it in GitHub Desktop.
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