generated from container/tmpl
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.4 KiB
47 lines
1.4 KiB
2 years ago
|
'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;
|
||
|
};
|