2016-08-20 05:08:46 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import Winston from 'winston';
|
|
|
|
|
2017-06-03 03:25:02 +08:00
|
|
|
const Logger = new Winston.Logger();
|
2016-08-20 05:08:46 +08:00
|
|
|
|
2016-12-01 00:29:13 +08:00
|
|
|
Logger.configure({
|
2018-01-08 08:25:56 +08:00
|
|
|
levels: {
|
|
|
|
error: 0, warn: 1, info: 2, verbose: 3, debug: 4,
|
|
|
|
},
|
2016-12-01 00:29:13 +08:00
|
|
|
colors: {
|
|
|
|
error: 'red',
|
|
|
|
warn: 'yellow',
|
|
|
|
info: 'green',
|
|
|
|
verbose: 'cyan',
|
|
|
|
debug: 'magenta',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2016-08-20 05:08:46 +08:00
|
|
|
Meteor.startup(() => {
|
2018-01-08 08:24:05 +08:00
|
|
|
const LOG_CONFIG = Meteor.settings.private.log || {};
|
2018-01-08 08:25:56 +08:00
|
|
|
let { filename } = LOG_CONFIG;
|
2018-01-30 05:48:15 +08:00
|
|
|
const { level } = LOG_CONFIG;
|
2016-08-20 05:08:46 +08:00
|
|
|
|
2018-01-30 05:48:15 +08:00
|
|
|
// console logging
|
|
|
|
if (Meteor.isDevelopment) {
|
|
|
|
Logger.add(Winston.transports.Console, {
|
|
|
|
prettyPrint: false,
|
|
|
|
humanReadableUnhandledException: true,
|
|
|
|
colorize: true,
|
|
|
|
handleExceptions: true,
|
|
|
|
level,
|
|
|
|
});
|
|
|
|
}
|
2016-12-02 00:15:57 +08:00
|
|
|
|
2018-01-30 05:48:15 +08:00
|
|
|
// file logging
|
2016-08-24 05:35:28 +08:00
|
|
|
if (filename) {
|
2018-01-30 05:48:15 +08:00
|
|
|
// no file rotation
|
2018-01-08 08:24:05 +08:00
|
|
|
if (Meteor.isDevelopment) {
|
2016-08-24 05:35:28 +08:00
|
|
|
const path = Npm.require('path');
|
|
|
|
filename = path.join(process.env.PWD, filename);
|
2018-01-30 05:48:15 +08:00
|
|
|
|
|
|
|
Logger.add(Winston.transports.File, {
|
|
|
|
filename,
|
|
|
|
prettyPrint: true,
|
|
|
|
level,
|
|
|
|
prepend: true,
|
|
|
|
});
|
2016-08-20 05:08:46 +08:00
|
|
|
}
|
|
|
|
|
2018-01-30 05:48:15 +08:00
|
|
|
// daily file rotation
|
|
|
|
if (Meteor.isProduction) {
|
|
|
|
Winston.transports.DailyRotateFile = Npm.require('winston-daily-rotate-file');
|
|
|
|
Logger.add(Winston.transports.DailyRotateFile, {
|
|
|
|
filename,
|
2018-01-30 23:37:00 +08:00
|
|
|
datePattern: '.yyyy-MM-dd',
|
2018-01-30 05:48:15 +08:00
|
|
|
prepend: false,
|
|
|
|
level,
|
|
|
|
});
|
|
|
|
}
|
2016-08-24 05:35:28 +08:00
|
|
|
}
|
2016-05-05 01:00:57 +08:00
|
|
|
});
|
2016-08-20 05:08:46 +08:00
|
|
|
|
|
|
|
export default Logger;
|
|
|
|
|
2017-06-03 03:25:02 +08:00
|
|
|
export const logger = Logger;
|