winston was borked

This commit is contained in:
Emily 2020-04-19 00:14:11 +10:00
parent 047b0be769
commit dc279467d5
2 changed files with 24 additions and 62 deletions

View file

@ -3,6 +3,9 @@
'use strict'
// remove this after we uncomment sentry
/* eslint-disable no-unused-vars */
// Check node.js version
if (Number(process.version.slice(1).split('.')[0]) < 12) {
console.log('NodeJS 12.0.0 or higher is required. Please update NodeJS on your system.')
@ -58,9 +61,9 @@ const init = async () => {
if (!file.endsWith('.js')) {
return
}
const response = client.loadCommand(file)
if (response) {
client.logger.error(response)
const res = client.loadCommand(file)
if (res) {
client.logger.error(res)
}
})
})

View file

@ -1,65 +1,24 @@
'use strict'
const { createLogger, format, transports, addColors } = require('winston')
require('winston-daily-rotate-file')
const fs = require('fs')
const { colorConsole } = require('tracer')
const colors = require('colors')
if (!fs.existsSync('logs')) {
fs.mkdirSync('logs')
}
const dailyRotateFileTransport = new transports.DailyRotateFile({
filename: 'logs/%DATE%.log',
datePattern: 'YYYY-MM-DD'
const logger = colorConsole({
format: [
'{{timestamp}} | {{title}} | {{file}} | {{message}}',
{
debug: `{{timestamp}} | ${'{{title}}'.magenta} | {{file}} | {{message}}`,
cmd: `{{timestamp}} | ${'{{title}}'.white} | {{file}} | {{message}}`,
info: `{{timestamp}} | ${'{{title}}'.cyan} | {{file}} | {{message}}`,
ready: `{{timestamp}} | ${'{{title}}'.green} | {{file}} | {{message}}`,
warn: `{{timestamp}} | ${'{{title}}'.yellow} | {{file}} | {{message}}`,
error: `{{timestamp}} | ${'{{title}}'.red} | {{file}} | {{message}}`,
fatal: `{{timestamp}} | ${'{{title}}'.red.bold} | {{file}} | {{message}}`
}
],
dateformat: 'yyyy-mm-dd"T"HH:MM:ss',
methods: ['cmd', 'debug', 'info', 'ready', 'warn', 'error', 'fatal'],
filters: [colors.white]
})
const customLevels = {
levels: {
fatal: 0,
error: 1,
warn: 2,
ready: 3,
info: 4,
cmd: 5,
debug: 6
},
colors: {
fatal: 'bold red',
error: 'red',
warn: 'yellow',
ready: 'green',
info: 'cyan',
cmd: 'white',
debug: 'magenta'
}
}
const logger = createLogger({
level: 'info',
levels: customLevels.levels,
format: format.combine(
format.timestamp({
format: 'YYYY-MM-DD HH:mm:ss'
}),
format.printf(info => `${info.timestamp} ${info.level}: ${info.message}`)
),
transports: [
new transports.Console({
level: 'info',
format: format.combine(
format.colorize(),
format.printf(
info => `${info.timestamp} ${info.level}: ${info.message}`
)
)
}),
dailyRotateFileTransport
]
})
addColors(customLevels.colors)
module.exports = logger