woomy-v2/bot/util/logger.js

53 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-10-17 01:17:05 +00:00
const { createLogger, format, transports, addColors } = require('winston');
2020-08-18 04:58:36 +00:00
2020-10-17 01:17:05 +00:00
const fmt = format.printf(({ level, message, timestamp }) => {
return '[' + timestamp + '] ' + level + ' ' + message;
2020-08-18 04:58:36 +00:00
});
const customLevels = {
2020-10-17 01:17:05 +00:00
levels: {
debug: 0,
cmd: 1,
info: 2,
ready: 3,
warn: 4,
error: 5
},
2020-08-18 04:58:36 +00:00
2020-10-17 05:00:41 +00:00
colours: {
2020-10-17 01:17:05 +00:00
debug: 'black magentaBG',
cmd: 'black whiteBG',
info: 'black cyanBG',
ready: 'black greenBG',
warn: 'black yellowBG',
error: 'black redBG'
}
2020-08-18 04:58:36 +00:00
};
const logger = createLogger({
2020-10-17 01:17:05 +00:00
levels: customLevels.levels,
level: 'error',
format: format.combine(
format.timestamp({
format: 'YYYY-MM-DD hh:mm:ss'
2020-08-18 04:58:36 +00:00
}),
fmt
2020-10-17 01:17:05 +00:00
),
transports: [
new transports.Console({
2020-10-17 05:00:41 +00:00
level: 'error',
format: format.combine(
format.timestamp({
format: 'YYYY-MM-DD hh:mm:ss'
}),
format.colorize(),
fmt
)
2020-10-17 01:17:05 +00:00
})
]
2020-08-18 04:58:36 +00:00
});
addColors(customLevels.colours);
module.exports = logger;