Last active
October 25, 2020 18:12
-
-
Save GlowingRain/9e6bbb6dcb14fa5014efe377ec035cfe to your computer and use it in GitHub Desktop.
Custom logger made with Wiston for Discord Bots
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { createLogger, format, transports, addColors } = require('winston'); | |
const { combine } = format; | |
// Levels | |
const customLevels = { | |
levels: { | |
error: 0, | |
warn: 1, | |
client: 2, | |
info: 3, | |
debug: 4, | |
trace: 5 | |
}, | |
colors: { | |
error: 'bold red', | |
warn: 'bold yellow', | |
client: 'bold magenta', | |
info: 'bold blue', | |
debug: 'bold gray', | |
trace: 'bold gray' | |
} | |
} | |
// Colors | |
addColors(customLevels.colors); | |
// Logger setup | |
const logger = new createLogger({ | |
level: 'info', | |
levels: customLevels.levels, | |
// Transports | |
transports: [ | |
// Console transport | |
new transports.Console({ | |
format: combine( | |
format(info => ({ ...info, level: `[${info.level.toUpperCase()}]` }))(), | |
format.colorize(), | |
format.errors({ stack: true }), | |
format.prettyPrint(), | |
format.simple(), | |
format.splat(), | |
format.timestamp({ format: "YYYY-MM-DD HH:mm:ss A" }), | |
format.printf( | |
({ timestamp, level, message }) => `[${timestamp}] ${level} - ${message}` | |
) | |
) | |
}), | |
// File transport. | |
// Absolutely not necessary as you would be wanting to restart your bot a lot when making changes. | |
new transports.File({ | |
filename: `${__dirname}/../../logs/aelis.log`, | |
format: combine( | |
format.timestamp({ format: 'DD-MM-YYYY hh:mm:ss' }), | |
format.printf(info => { return `[${info.timestamp}] [${info.level}] - ${info.message}` }) | |
) | |
}), | |
new transports.File({ | |
filename: `${__dirname}/../../logs/aelis_errors.log`, | |
level: 'error', | |
format: combine( | |
format.timestamp({ format: 'DD-MM-YYYY hh:mm:ss' }), | |
format.printf(info => { return `[${info.timestamp}] [${info.level}] - ${info.message}` }) | |
) | |
}) | |
] | |
}); | |
module.exports = logger; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment