1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| const options = { name: 'app', module: 'app', filePath: './logs', formatter: meta => { return `${meta.timestamp} ${meta.level} ${meta.hostname} ${meta.pid} (${meta.ms}) [${ meta.module }] ${meta.message}`; }, consoleLevel: 'error', json: false, };
const consoleTransport = new ConsoleTransport({ level: options.consoleLevel, name: options.name, formatter: options.consoleFormatter, });
const infoTransport = new FileTransport({ level: 'info', name: options.name, filename: join(options.filePath, `info/${options.name}-info-%DATE%.log`), formatter: options.formatter, json: options.json, });
const errorTransport = new FileTransport({ level: 'error', name: options.name, filename: join(options.filePath, 'error/error-%DATE%.log'), formatter: options.formatter, json: options.json, });
const transports = [consoleTransport, infoTransport, errorTransport]; const logger = winston.createLogger({ transports });
logger.info('log1'); logger.error('error 1');
|