'use strict'; const winston = require('winston'); const fs = require('fs'); const path = require('path'); const moment = require('moment'); module.exports = function (config) { const defaultConfig = require('../../config').logger; config = config || defaultConfig; config.level = config.level || 'error'; config.filename = config.filename || path.join(process.cwd(), "log", "runtime.log"); let dir = path.dirname(config.filename); let logger = {}; try { if (!fs.existsSync(dir)) { fs.mkdirSync(dir); } logger = new (winston.Logger)({ level: config.level, transports: [ new (winston.transports.Console)({ colorize: 'all', timestamp: () => moment().format('YYYY-MM-DD HH:mm:ss.SSS') }), new (winston.transports.File)(config) ], exitOnError: false }); } catch (err) { console.log(err); logger = new (winston.Logger)({ level: config.level, transports: [ new (winston.transports.Console)({ colorize: 'all', timestamp: () => moment().format('YYYY-MM-DD HH:mm:ss.SSS') }) ], exitOnError: false }); } logger.log('debug', '[LOGGER]', 'Init.'); process.logger = logger; return logger; };