galactic-bot/structure/client/Logger.js

67 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-04-12 14:34:26 +02:00
const chalk = require('chalk');
class Logger {
constructor(client) {
this.client = client;
2020-04-13 22:38:10 +02:00
this.client.eventHooker.hook('ready', () => {
2020-04-14 05:25:17 +02:00
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'}`)}.`);
2020-04-12 14:34:26 +02:00
});
2020-04-13 22:38:10 +02:00
this.client.eventHooker.hook('componentUpdate', ({ component, type }) => {
2020-04-12 14:34:26 +02:00
this.info(`Component ${chalk.bold(component.resolveable)} was ${chalk.bold(Constants.ComponentTypes[type])}.`);
});
2020-04-13 22:38:10 +02:00
this.client.eventHooker.hook('reconnect', () => {
this.warn(`Shard is reconnecting.`);
2020-04-12 14:34:26 +02:00
});
}
async transport(message = 'N/A', opts = {}) {
process.send({ _logger: true, message, ...opts });
2020-04-12 14:34:26 +02:00
}
/* Quick & Dirty Functions */
2020-04-13 22:38:10 +02:00
silly(message, opts = {}) {
this.transport(message, { ...opts, type: 'silly' });
2020-04-12 14:34:26 +02:00
}
2020-04-13 22:38:10 +02:00
debug(message, opts = {}) {
this.transport(message, { ...opts, type: 'debug' });
2020-04-12 14:34:26 +02:00
}
2020-04-13 22:38:10 +02:00
verbose(message, opts = {}) {
this.transport(message, { ...opts, type: 'verbose' });
2020-04-12 14:34:26 +02:00
}
2020-04-13 22:38:10 +02:00
info(message, opts = {}) {
this.transport(message, { ...opts, type: 'info' });
}
warn(message, opts = {}) {
this.transport(message, { ...opts, type: 'warn' });
2020-04-12 14:34:26 +02:00
}
error(message, opts = {}) {
2020-04-13 22:38:10 +02:00
this.transport(message, { ...opts, type: 'error' });
2020-04-12 14:34:26 +02:00
}
}
module.exports = Logger;
const Constants = {
ComponentTypes: {
LOAD: 'loaded',
UNLOAD: 'unloaded',
RELOAD: 'reloaded',
ENABLE: 'enabled',
DISABLE: 'disabled'
}
};