forked from Galactic/galactic-bot
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
/* eslint-disable max-len */
|
|
const chalk = require('chalk');
|
|
const { inspect } = require('util');
|
|
|
|
class Logger {
|
|
|
|
constructor(client) {
|
|
|
|
this.client = client;
|
|
this.name = (client.name || client.constructor.name).toUpperCase();
|
|
|
|
}
|
|
|
|
async transport(message = 'N/A', opts = {}) {
|
|
if (typeof message !== 'string') message = inspect(message);
|
|
message = `${chalk.bold(`[${this.name.substring(0, 6)}]`)} ${message}`;
|
|
|
|
|
|
// eslint-disable-next-line no-console, no-process-exit
|
|
if (!process.send || !process.connected) process.exit(); // Child-process disconnected for some reason //console.log(message);
|
|
else process.send({ _logger: true, message, ...opts });
|
|
//return this.client.intercom.send('logger', { message, ...opts });
|
|
}
|
|
|
|
/* Quick & Dirty Functions */
|
|
|
|
warn(message, opts = {}) {
|
|
this.transport(message, { ...opts, type: 'warn' });
|
|
}
|
|
|
|
error(message, opts = {}) {
|
|
this.transport(message, { ...opts, type: 'error' });
|
|
}
|
|
|
|
debug(message, opts = {}) {
|
|
this.transport(message, { ...opts, type: 'debug' });
|
|
}
|
|
|
|
info(message, opts = {}) {
|
|
this.transport(message, { ...opts, type: 'info' });
|
|
}
|
|
|
|
status(message, opts = {}) {
|
|
this.transport(message, { ...opts, type: 'status' });
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = Logger; |