UNPKG

@misterzik/espressojs

Version:

EspressoJS Introducing Espresso.JS, your ultimate Express configuration starting point and boilerplate. With its simplicity and lack of opinionation, EspressoJS offers plug-and-play configurations built on top of Express.

76 lines (66 loc) 1.69 kB
/* * _| _| _| _| _|_|_| * _| _| _|_| _|_| _| _| * _| _| _| _| _| _| _| * _| _| _| _| _| _| * _| _| _| _|_|_| * EspressoJS - Logger Utility */ const winston = require("winston"); const path = require("path"); const logLevels = { error: 0, warn: 1, info: 2, http: 3, debug: 4, }; const logColors = { error: "red", warn: "yellow", info: "green", http: "magenta", debug: "blue", }; winston.addColors(logColors); const logFormat = winston.format.combine( winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), winston.format.colorize({ all: true }), winston.format.printf( (info) => `${info.timestamp} [${info.level}]: ${info.message}` ) ); const fileFormat = winston.format.combine( winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), winston.format.json() ); const transports = [ new winston.transports.Console({ format: logFormat, }), new winston.transports.File({ filename: path.join(process.cwd(), "logs", "error.log"), level: "error", format: fileFormat, }), new winston.transports.File({ filename: path.join(process.cwd(), "logs", "combined.log"), format: fileFormat, }), ]; const logger = winston.createLogger({ level: process.env.NODE_ENV === "production" ? "info" : "debug", levels: logLevels, transports, exceptionHandlers: [ new winston.transports.File({ filename: path.join(process.cwd(), "logs", "exceptions.log"), }), ], rejectionHandlers: [ new winston.transports.File({ filename: path.join(process.cwd(), "logs", "rejections.log"), }), ], }); module.exports = logger;