UNPKG

js-mvc-app

Version:

A CLI tool to scaffold complete Node.js MVC projects with TypeScript, just like Laravel

96 lines (86 loc) 2.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getLogger = getLogger; function getLogger() { return `import winston from 'winston'; // Define log levels const levels = { error: 0, warn: 1, info: 2, http: 3, debug: 4 }; // Define colors for each level const colors = { error: 'red', warn: 'yellow', info: 'green', http: 'magenta', debug: 'white' }; // Add colors to winston winston.addColors(colors); // Define log format const format = winston.format.combine( winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss:ms' }), winston.format.colorize({ all: true }), winston.format.printf( (info) => \`\${info.timestamp} \${info.level}: \${info.message}\` ) ); // Define transports const transports = [ // Console transport new winston.transports.Console({ format: winston.format.combine( winston.format.colorize(), winston.format.simple() ) }), // File transport for errors new winston.transports.File({ filename: 'logs/error.log', level: 'error', format: winston.format.combine( winston.format.timestamp(), winston.format.json() ) }), // File transport for all logs new winston.transports.File({ filename: 'logs/combined.log', format: winston.format.combine( winston.format.timestamp(), winston.format.json() ) }) ]; // Create logger export const logger = winston.createLogger({ level: process.env.LOG_LEVEL || 'info', levels, format, transports, exceptionHandlers: [ new winston.transports.File({ filename: 'logs/exceptions.log' }) ], rejectionHandlers: [ new winston.transports.File({ filename: 'logs/rejections.log' }) ] }); // If not in production, log to console as well if (process.env.NODE_ENV !== 'production') { logger.add(new winston.transports.Console({ format: winston.format.simple() })); } // Stream for morgan HTTP logging export const stream = { write: (message: string) => { logger.http(message.trim()); } }; `; } //# sourceMappingURL=logger.js.map