2022-01-27 00:13:42 +01:00
|
|
|
/* eslint-disable max-len */
|
2020-04-12 14:34:26 +02:00
|
|
|
const chalk = require('chalk');
|
2022-01-27 00:13:42 +01:00
|
|
|
const { inspect } = require('util');
|
2020-04-12 14:34:26 +02:00
|
|
|
|
|
|
|
class Logger {
|
|
|
|
|
|
|
|
constructor(client) {
|
|
|
|
|
|
|
|
this.client = client;
|
2022-03-26 21:10:32 +01:00
|
|
|
this.name = (client.name || client.constructor.name).toUpperCase();
|
2020-07-20 03:25:27 +02:00
|
|
|
|
2020-04-12 14:34:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async transport(message = 'N/A', opts = {}) {
|
2022-01-27 00:13:42 +01:00
|
|
|
if (typeof message !== 'string') message = inspect(message);
|
2022-03-15 01:00:45 +01:00
|
|
|
message = `${chalk.bold(`[${this.name.substring(0, 6)}]`)} ${message}`;
|
|
|
|
|
2022-04-27 19:06:54 +02:00
|
|
|
|
2023-04-05 16:33:46 +02:00
|
|
|
// 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);
|
2022-04-27 19:06:54 +02:00
|
|
|
else process.send({ _logger: true, message, ...opts });
|
2022-03-15 01:00:45 +01:00
|
|
|
//return this.client.intercom.send('logger', { message, ...opts });
|
2020-04-12 14:34:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Quick & Dirty Functions */
|
|
|
|
|
2021-08-16 23:01:08 +02:00
|
|
|
warn(message, opts = {}) {
|
|
|
|
this.transport(message, { ...opts, type: 'warn' });
|
2020-04-12 14:34:26 +02:00
|
|
|
}
|
|
|
|
|
2021-08-16 23:01:08 +02:00
|
|
|
error(message, opts = {}) {
|
|
|
|
this.transport(message, { ...opts, type: 'error' });
|
2020-04-12 14:34:26 +02:00
|
|
|
}
|
|
|
|
|
2021-08-16 23:01:08 +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
|
|
|
info(message, opts = {}) {
|
|
|
|
this.transport(message, { ...opts, type: 'info' });
|
|
|
|
}
|
|
|
|
|
2021-08-16 23:01:08 +02:00
|
|
|
status(message, opts = {}) {
|
|
|
|
this.transport(message, { ...opts, type: 'status' });
|
2020-04-12 14:34:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-08-08 00:21:28 +02:00
|
|
|
module.exports = Logger;
|