forked from Galactic/galactic-bot
logger changes and testing
This commit is contained in:
parent
194942f5c4
commit
aa03afc832
@ -1,15 +1,16 @@
|
|||||||
{
|
{
|
||||||
"env": {
|
"env": {
|
||||||
|
"commonjs": true,
|
||||||
"es6": true,
|
"es6": true,
|
||||||
"node": true
|
"node": true
|
||||||
},
|
},
|
||||||
"extends": "eslint:recommended",
|
"extends": "eslint:recommended",
|
||||||
|
"globals": {
|
||||||
|
"Atomics": "readonly",
|
||||||
|
"SharedArrayBuffer": "readonly"
|
||||||
|
},
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
"sourceType": "module",
|
"ecmaVersion": 2018
|
||||||
"ecmaVersion": 2018,
|
|
||||||
"ecmaFeatures": {
|
|
||||||
"experimentalObjectRestSpread": true
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
"indent": [
|
"indent": [
|
||||||
@ -21,7 +22,7 @@
|
|||||||
"unix"
|
"unix"
|
||||||
],
|
],
|
||||||
"semi": [
|
"semi": [
|
||||||
"warn",
|
"error",
|
||||||
"always"
|
"always"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,7 @@ const { EventEmitter } = require('events');
|
|||||||
|
|
||||||
const ShardManager = require('./middleware/ShardManager.js');
|
const ShardManager = require('./middleware/ShardManager.js');
|
||||||
const StorageManager = require('./storage/StorageManager.js');
|
const StorageManager = require('./storage/StorageManager.js');
|
||||||
const Logger = require('./Logger.js');
|
const Logger = require('./middleware/logger/Logger.js');
|
||||||
|
|
||||||
const { Command, Setting, Inhibitor } = require('./structure/interfaces/');
|
|
||||||
|
|
||||||
class Manager extends EventEmitter {
|
class Manager extends EventEmitter {
|
||||||
|
|
||||||
|
37
logs/what.log
Normal file
37
logs/what.log
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
info: Why tf isnt this working...
|
||||||
|
info: Component [1mmodule:utility[22m was [1mloaded[22m.
|
||||||
|
info: Component [1mcommand:ping[22m was [1mloaded[22m.
|
||||||
|
info: Component [1mobserver:commandHandler[22m was [1mloaded[22m.
|
||||||
|
info: Client connected to [1masfasf#1551[22m with [1mundefined guilds[22m.
|
||||||
|
info: Why tf isnt this working...
|
||||||
|
error: THERES A FUCKIN ERROR
|
||||||
|
info: Component [1mmodule:utility[22m was [1mloaded[22m.
|
||||||
|
info: Component [1mcommand:ping[22m was [1mloaded[22m.
|
||||||
|
info: Component [1mobserver:commandHandler[22m was [1mloaded[22m.
|
||||||
|
info: Client connected to [1masfasf#1551[22m with [1mundefined guilds[22m.
|
||||||
|
info: Why tf isnt this working...
|
||||||
|
error: THERES A FUCKIN ERROR
|
||||||
|
info: Why tf isnt this working...
|
||||||
|
error: THERES A FUCKIN ERROR
|
||||||
|
info: [38;2;97;153;36m[04-12-2020 08:38:18][shard-00][39m Component [1mmodule:utility[22m was [1mloaded[22m.
|
||||||
|
info: [38;2;97;153;36m[04-12-2020 08:38:18][shard-00][39m Component [1mcommand:ping[22m was [1mloaded[22m.
|
||||||
|
info: [38;2;97;153;36m[04-12-2020 08:38:18][shard-00][39m Component [1mobserver:commandHandler[22m was [1mloaded[22m.
|
||||||
|
info: [38;2;97;153;36m[04-12-2020 08:38:18][shard-00][39m Client connected to [1masfasf#1551[22m with [1mundefined guilds[22m.
|
||||||
|
info: Why tf isnt this working...
|
||||||
|
error: THERES A FUCKIN ERROR
|
||||||
|
info: [38;2;97;153;36m[04-12-2020 08:39:00][shard-00][39m Component [1mmodule:utility[22m was [1mloaded[22m.
|
||||||
|
info: [38;2;97;153;36m[04-12-2020 08:39:00][shard-00][39m Component [1mcommand:ping[22m was [1mloaded[22m.
|
||||||
|
info: [38;2;97;153;36m[04-12-2020 08:39:00][shard-00][39m Component [1mobserver:commandHandler[22m was [1mloaded[22m.
|
||||||
|
info: [38;2;97;153;36m[04-12-2020 08:39:00][shard-00][39m Client connected to [1masfasf#1551[22m with [1mundefined guilds[22m.
|
||||||
|
info: Why tf isnt this working...
|
||||||
|
error: THERES A FUCKIN ERROR
|
||||||
|
info: [38;2;97;153;36m[04-12-2020 08:39:24][shard-00][39m Component [1mmodule:utility[22m was [1mloaded[22m.
|
||||||
|
info: [38;2;97;153;36m[04-12-2020 08:39:24][shard-00][39m Component [1mcommand:ping[22m was [1mloaded[22m.
|
||||||
|
info: [38;2;97;153;36m[04-12-2020 08:39:24][shard-00][39m Component [1mobserver:commandHandler[22m was [1mloaded[22m.
|
||||||
|
info: [38;2;97;153;36m[04-12-2020 08:39:24][shard-00][39m Client connected to [1masfasf#1551[22m with [1mundefined guilds[22m.
|
||||||
|
info: Why tf isnt this working...
|
||||||
|
error: THERES A FUCKIN ERROR
|
||||||
|
info: [34m[04-12-2020 08:41:07][shard-00][39m Component [1mmodule:utility[22m was [1mloaded[22m.
|
||||||
|
info: [34m[04-12-2020 08:41:07][shard-00][39m Component [1mcommand:ping[22m was [1mloaded[22m.
|
||||||
|
info: [34m[04-12-2020 08:41:07][shard-00][39m Component [1mobserver:commandHandler[22m was [1mloaded[22m.
|
||||||
|
info: [34m[04-12-2020 08:41:07][shard-00][39m Client connected to [1masfasf#1551[22m with [1mundefined guilds[22m.
|
@ -3,23 +3,37 @@ const { combine, label, printf } = format;
|
|||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
const chalk = require('chalk');
|
const chalk = require('chalk');
|
||||||
|
|
||||||
|
const { DiscordWebhook } = require('./transports/');
|
||||||
|
|
||||||
|
const regex = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g //removes chalk formatting, will be used for the log FILES.
|
||||||
|
|
||||||
class Logger {
|
class Logger {
|
||||||
|
|
||||||
constructor(manager) {
|
constructor(manager) {
|
||||||
|
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
|
this.shardManager = manager.shardManager;
|
||||||
|
|
||||||
this.logger = createLogger({
|
this.logger = createLogger({
|
||||||
|
format: (
|
||||||
|
format.simple()
|
||||||
|
),
|
||||||
transports: [
|
transports: [
|
||||||
new transports.Console(),
|
new transports.Console(),
|
||||||
new transports.File({ filename: `logs/${this.date.replace(/ /g, '-')}.log` }),
|
new transports.File({ filename: `logs/what.log` }),
|
||||||
new transports.File({ filename: `logs/${this.date.replace(/ /g, '-')}-error.log`, level: 'error' })
|
new transports.File({ filename: `logs/${this.date.replace(/ /g, '-')}-error.log`, level: 'error' }),
|
||||||
|
new DiscordWebhook({ level: 'error' }) //Broadcast errors to a discord webhook.
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
this.client
|
this.shardManager
|
||||||
.on('shardCreate', (shard) => this.write(shard, "Shard created.", 'DEBUG'))
|
.on('shardCreate', (shard) => this.write(shard, "Shard created.", 'debug'))
|
||||||
.on('message', (shard, message) => this._handleMessage(shard, message));
|
.on('message', (shard, message) => this._handleMessage(shard, message));
|
||||||
|
|
||||||
|
console.log("FUCK");
|
||||||
|
this.logger.log('info', "Why tf isnt this working...");
|
||||||
|
this.logger.log('error', "THERES A FUCKIN ERROR");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Messages coming from the shards process.send functions.
|
//Messages coming from the shards process.send functions.
|
||||||
@ -31,7 +45,7 @@ class Logger {
|
|||||||
|| message._sEval
|
|| message._sEval
|
||||||
|| message._sRespawnAll) return undefined; //Properties used for discord.js internal sharding, must filter for.
|
|| message._sRespawnAll) return undefined; //Properties used for discord.js internal sharding, must filter for.
|
||||||
|
|
||||||
|
await this.write(shard, message.message, message.type);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,10 +53,11 @@ class Logger {
|
|||||||
async write(shard, string = '', type = 'silly') {
|
async write(shard, string = '', type = 'silly') {
|
||||||
if(!config.npm.levels[type]) return undefined;
|
if(!config.npm.levels[type]) return undefined;
|
||||||
|
|
||||||
const header = `[${this.date}][shard-${this._shardId(shard)}]`;
|
const color = Constants.Colors[type];
|
||||||
|
const header = `${chalk[color](`[${this.date}][shard-${this._shardId(shard)}]`)}`;
|
||||||
//[04/02/2020 12:52:20][shard-00]
|
//[04/02/2020 12:52:20][shard-00]
|
||||||
|
|
||||||
this.logger.log(type, string)
|
this.logger.log(type, `${header} ${string}`)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,4 +72,26 @@ class Logger {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Logger;
|
module.exports = Logger;
|
||||||
|
|
||||||
|
const Constants = {
|
||||||
|
Colors: {
|
||||||
|
error: 'red',
|
||||||
|
warn: 'yellow',
|
||||||
|
info: 'blue',
|
||||||
|
verbose: 'cyan',
|
||||||
|
debug: 'magenta',
|
||||||
|
silly: 'magentaBright'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
const levels = {
|
||||||
|
error: 0,
|
||||||
|
warn: 1,
|
||||||
|
info: 2,
|
||||||
|
http: 3,
|
||||||
|
verbose: 4,
|
||||||
|
debug: 5,
|
||||||
|
silly: 6
|
||||||
|
};*/
|
24
middleware/logger/transports/DiscordWebhook.js
Normal file
24
middleware/logger/transports/DiscordWebhook.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
const Transport = require('winston-transport');
|
||||||
|
|
||||||
|
class DiscordWebhook extends Transport {
|
||||||
|
constructor(opts) {
|
||||||
|
super(opts);
|
||||||
|
//
|
||||||
|
// Consume any custom options here. e.g.:
|
||||||
|
// - Connection information for databases
|
||||||
|
// - Authentication information for APIs (e.g. loggly, papertrail,
|
||||||
|
// logentries, etc.).
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
log(info, callback) {
|
||||||
|
setImmediate(() => {
|
||||||
|
this.emit('logged', info);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Perform the writing to the remote service
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = DiscordWebhook;
|
3
middleware/logger/transports/index.js
Normal file
3
middleware/logger/transports/index.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
module.exports = {
|
||||||
|
DiscordWebhook: require('./DiscordWebhook.js')
|
||||||
|
}
|
@ -27,6 +27,7 @@
|
|||||||
"mongodb": "^3.5.5",
|
"mongodb": "^3.5.5",
|
||||||
"mysql": "^2.18.1",
|
"mysql": "^2.18.1",
|
||||||
"node-fetch": "^2.6.0",
|
"node-fetch": "^2.6.0",
|
||||||
"winston": "^3.2.1"
|
"winston": "^3.2.1",
|
||||||
|
"winston-transport": "^4.3.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ const Registry = require('./Registry.js')
|
|||||||
const EventHooker = require('./EventHooker.js');
|
const EventHooker = require('./EventHooker.js');
|
||||||
const Dispatcher = require('./Dispatcher.js')
|
const Dispatcher = require('./Dispatcher.js')
|
||||||
const Resolver = require('./Resolver.js');
|
const Resolver = require('./Resolver.js');
|
||||||
const Transporter = require('./Transporter.js');
|
const Logger = require('./Logger.js');
|
||||||
|
|
||||||
const { Guild, User, Message } = require('../../structure/extensions/');
|
const { Guild, User, Message } = require('../../structure/extensions/');
|
||||||
const { Command, Observer, Inhibitor, Setting } = require('../../structure/interfaces/');
|
const { Command, Observer, Inhibitor, Setting } = require('../../structure/interfaces/');
|
||||||
@ -21,7 +21,7 @@ class DiscordClient extends Client {
|
|||||||
this.eventHooker = new EventHooker(this);
|
this.eventHooker = new EventHooker(this);
|
||||||
this.dispatcher = new Dispatcher(this);
|
this.dispatcher = new Dispatcher(this);
|
||||||
this.resolver = new Resolver(this);
|
this.resolver = new Resolver(this);
|
||||||
this.transporter = new Transporter(this);
|
this.logger = new Logger(this);
|
||||||
|
|
||||||
this._options = options;
|
this._options = options;
|
||||||
this._built = false;
|
this._built = false;
|
||||||
@ -47,10 +47,6 @@ class DiscordClient extends Client {
|
|||||||
console.log('Client websocket is ready.');
|
console.log('Client websocket is ready.');
|
||||||
});
|
});
|
||||||
|
|
||||||
this.registry.on('componentUpdate', (comp, type) => {
|
|
||||||
console.log(`[registry][${type}] ${comp.resolveable}`)
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('Client built');
|
console.log('Client built');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,16 +6,16 @@ class Logger {
|
|||||||
|
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
|
||||||
this.client.hooker.hook('ready', () => {
|
this.client.eventHooker.hook('ready', () => {
|
||||||
this.transport(`Client connected to ${chalk.bold(this.client.user.tag)} with ${chalk.bold(`${this.client.guilds.size} guild${this.client.guilds.size === 1 ? '' : 's'}`)}.`, { embed: true, type: 'SUCCESS' });
|
this.info(`Client connected to ${chalk.bold(this.client.user.tag)} with ${chalk.bold(`${this.client.guilds.size} guild${this.client.guilds.size === 1 ? '' : 's'}`)}.`);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.client.hooker.hook('componentUpdate', ({ component, type }) => {
|
this.client.eventHooker.hook('componentUpdate', ({ component, type }) => {
|
||||||
this.info(`Component ${chalk.bold(component.resolveable)} was ${chalk.bold(Constants.ComponentTypes[type])}.`);
|
this.info(`Component ${chalk.bold(component.resolveable)} was ${chalk.bold(Constants.ComponentTypes[type])}.`);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.client.hooker.hook('reconnect', () => {
|
this.client.eventHooker.hook('reconnect', () => {
|
||||||
this.warn(`Shard is reconnecting.`, { embed: true });
|
this.warn(`Shard is reconnecting.`);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -26,24 +26,28 @@ class Logger {
|
|||||||
|
|
||||||
/* Quick & Dirty Functions */
|
/* Quick & Dirty Functions */
|
||||||
|
|
||||||
log(message, opts = {}) {
|
silly(message, opts = {}) {
|
||||||
this.transport(message, { ...opts, type: 'LOG' });
|
this.transport(message, { ...opts, type: 'silly' });
|
||||||
}
|
|
||||||
|
|
||||||
info(message, opts = {}) {
|
|
||||||
this.transport(message, { ...opts, type: 'INFO' });
|
|
||||||
}
|
|
||||||
|
|
||||||
warn(message, opts = {}) {
|
|
||||||
this.transport(message, { ...opts, type: 'WARN' });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
debug(message, opts = {}) {
|
debug(message, opts = {}) {
|
||||||
this.transport(message, { ...opts, type: 'DEBUG' });
|
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 = {}) {
|
error(message, opts = {}) {
|
||||||
this.transport(message, { ...opts, type: 'ERROR' });
|
this.transport(message, { ...opts, type: 'error' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,16 +1,13 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const { EventEmitter } = require('events');
|
|
||||||
const { Collection, Util } = require('../../util/');
|
const { Collection, Util } = require('../../util/');
|
||||||
|
|
||||||
const { Component, Module } = require('../../structure/interfaces');
|
const { Component, Module } = require('../../structure/interfaces');
|
||||||
|
|
||||||
class Registry extends EventEmitter {
|
class Registry {
|
||||||
|
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
|
|
||||||
super();
|
|
||||||
|
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.components = new Collection();
|
this.components = new Collection();
|
||||||
|
|
||||||
@ -67,7 +64,7 @@ class Registry extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.components.set(component.resolveable, component);
|
this.components.set(component.resolveable, component);
|
||||||
this.emit('componentUpdate', { component, type: 'LOAD' });
|
this.client.emit('componentUpdate', { component, type: 'LOAD' });
|
||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,8 @@ class PingCommand extends Command {
|
|||||||
new Argument(client, {
|
new Argument(client, {
|
||||||
name: 'apple',
|
name: 'apple',
|
||||||
type: 'BOOLEAN',
|
type: 'BOOLEAN',
|
||||||
types: ['VERBAL']
|
types: ['VERBAL', 'FLAG'],
|
||||||
|
default: true
|
||||||
}),
|
}),
|
||||||
new Argument(client, {
|
new Argument(client, {
|
||||||
name: 'banana',
|
name: 'banana',
|
||||||
|
@ -20,14 +20,14 @@ class Component {
|
|||||||
enable() {
|
enable() {
|
||||||
if(this.guarded) return { error: true, code: 'GUARDED' };
|
if(this.guarded) return { error: true, code: 'GUARDED' };
|
||||||
this.disabled = false;
|
this.disabled = false;
|
||||||
this.registry.emit('componentUpdate', { component: this, type: 'ENABLE' });
|
this.client.emit('componentUpdate', { component: this, type: 'ENABLE' });
|
||||||
return { error: false };
|
return { error: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
disable() {
|
disable() {
|
||||||
if(this.guarded) return { error: true, code: 'GUARDED' };
|
if(this.guarded) return { error: true, code: 'GUARDED' };
|
||||||
this.disabled = true;
|
this.disabled = true;
|
||||||
this.registry.emit('componentUpdate', { component: this, type: 'DISABLE' });
|
this.client.emit('componentUpdate', { component: this, type: 'DISABLE' });
|
||||||
return { error: false };
|
return { error: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ class Component {
|
|||||||
this.registry.unloadComponent(this);
|
this.registry.unloadComponent(this);
|
||||||
delete require.cache[this.filePath];
|
delete require.cache[this.filePath];
|
||||||
|
|
||||||
this.registry.emit('componentUpdate', { component: this, type: 'UNLOAD' });
|
this.client.emit('componentUpdate', { component: this, type: 'UNLOAD' });
|
||||||
return { error: false };
|
return { error: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ class Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.registry.unloadComponent(this);
|
this.registry.unloadComponent(this);
|
||||||
this.registry.emit('componentUpdate', { component: this, type: 'UNLOAD' });
|
this.client.emit('componentUpdate', { component: this, type: 'UNLOAD' });
|
||||||
this.registry.loadComponent(newModule, this.directory);
|
this.registry.loadComponent(newModule, this.directory);
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
if(cached) require.cache[this.directory] = cached;
|
if(cached) require.cache[this.directory] = cached;
|
||||||
|
Loading…
Reference in New Issue
Block a user