galactic-bot/structure/client/Logger.js

67 lines
1.7 KiB
JavaScript

const chalk = require('chalk');
class Logger {
constructor(client) {
this.client = client;
this.client.eventHooker.hook('ready', () => {
const guilds = this.client.guilds.cache.size;
this.info(`Client connected to ${chalk.bold(this.client.user.tag)} with ${chalk.bold(`${guilds} guild${guilds === 1 ? '' : 's'}`)}.`);
});
this.client.eventHooker.hook('componentUpdate', ({ component, type }) => {
this.info(`Component ${chalk.bold(component.resolveable)} was ${chalk.bold(Constants.ComponentTypes[type])}.`); //eslint-disable-line no-use-before-define
});
this.client.eventHooker.hook('reconnect', () => {
this.warn(`Shard is reconnecting.`);
});
}
async transport(message = 'N/A', opts = {}) {
process.send({ _logger: true, message, ...opts });
}
/* Quick & Dirty Functions */
silly(message, opts = {}) {
this.transport(message, { ...opts, type: 'silly' });
}
debug(message, opts = {}) {
this.transport(message, { ...opts, type: 'debug' });
}
verbose(message, opts = {}) {
this.transport(message, { ...opts, type: 'verbose' });
}
info(message, opts = {}) {
this.transport(message, { ...opts, type: 'info' });
}
warn(message, opts = {}) {
this.transport(message, { ...opts, type: 'warn' });
}
error(message, opts = {}) {
this.transport(message, { ...opts, type: 'error' });
}
}
module.exports = Logger;
const Constants = {
ComponentTypes: {
LOAD: 'loaded',
UNLOAD: 'unloaded',
RELOAD: 'reloaded',
ENABLE: 'enabled',
DISABLE: 'disabled'
}
};