forked from Galactic/galactic-bot
logging changes
This commit is contained in:
parent
fffdaf5711
commit
4da152f7cc
1
logs/error.log
Normal file
1
logs/error.log
Normal file
@ -0,0 +1 @@
|
||||
|
@ -1,37 +1,5 @@
|
||||
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.
|
||||
debug: [04-13-2020 09:24:35][shard00] : Shard created.
|
||||
info: [04-13-2020 09:24:35][shard00] : Component module:utility was loaded.
|
||||
info: [04-13-2020 09:24:35][shard00] : Component command:ping was loaded.
|
||||
info: [04-13-2020 09:24:35][shard00] : Component observer:commandHandler was loaded.
|
||||
info: [04-13-2020 09:24:35][shard00] : Client connected to asfasf#1551 with 1 guild.
|
||||
|
@ -3,9 +3,7 @@ const { combine, label, printf } = format;
|
||||
const moment = require('moment');
|
||||
const chalk = require('chalk');
|
||||
|
||||
const { DiscordWebhook, ExtendedConsole } = 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.
|
||||
const { DiscordWebhook, FileExtension } = require('./transports/');
|
||||
|
||||
class Logger {
|
||||
|
||||
@ -15,26 +13,33 @@ class Logger {
|
||||
this.shardManager = manager.shardManager;
|
||||
|
||||
this.logger = createLogger({
|
||||
levels: config.npm.levels,
|
||||
format: (
|
||||
format.simple()
|
||||
format.cli({
|
||||
colors: {
|
||||
error: 'red',
|
||||
warn: 'yellow',
|
||||
info: 'blue',
|
||||
verbose: 'cyan',
|
||||
debug: 'magenta',
|
||||
silly: 'magentaBright'
|
||||
}
|
||||
})
|
||||
),
|
||||
transports: [
|
||||
new ExtendedConsole(),
|
||||
//new transports.Console(),
|
||||
new transports.File({ filename: `logs/what.log` }),
|
||||
new transports.File({ filename: `logs/${this.date.replace(/ /g, '-')}-error.log`, level: 'error' }),
|
||||
new FileExtension({ filename: `logs/what.log`, level: 'debug'}), //Will NOT log "silly" logs, could change in future.
|
||||
new FileExtension({ filename: `logs/error.log` , level: 'error' }),
|
||||
new transports.Console({ level: 'silly' }), //Will log EVERYTHING.
|
||||
new DiscordWebhook({ level: 'error' }) //Broadcast errors to a discord webhook.
|
||||
]
|
||||
});
|
||||
|
||||
//TODO: Add proper date-oriented filenames and add a daily rotation file (?).
|
||||
|
||||
this.shardManager
|
||||
.on('shardCreate', (shard) => this.write(shard, "Shard created.", 'debug'))
|
||||
.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.
|
||||
@ -44,21 +49,21 @@ class Logger {
|
||||
|| message._reconnecting
|
||||
|| message._sFetchProp
|
||||
|| message._sEval
|
||||
|| message._sRespawnAll) return undefined; //Properties used for discord.js internal sharding, must filter for.
|
||||
|| message._sRespawnAll
|
||||
|| message._storage
|
||||
|| message._webhook) return undefined; //Properties used for discord.js internal sharding & our own structures. must filter for.
|
||||
|
||||
await this.write(shard, message.message, message.type);
|
||||
|
||||
}
|
||||
|
||||
//The MAIN function for writing everything to the logger.
|
||||
async write(shard, string = '', type = 'silly') {
|
||||
if(!config.npm.levels[type]) return undefined;
|
||||
|
||||
const color = Constants.Colors[type];
|
||||
const header = `[${this.date}][shard-${this._shardId(shard)}]`;//`${chalk[color](`[${this.date}][shard-${this._shardId(shard)}]`)}`;
|
||||
//[04/02/2020 12:52:20][shard-00]
|
||||
const header = `${chalk[color](`[${this.date}][${shard ? `shard${this._shardId(shard)}` : 'manager'}]`)}`;
|
||||
|
||||
this.logger.log(type, `${header} ${string}`);
|
||||
|
||||
this.logger.log(type, `${header} : ${string}`);
|
||||
|
||||
}
|
||||
|
||||
@ -86,13 +91,12 @@ const Constants = {
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
const levels = {
|
||||
error: 0,
|
||||
warn: 1,
|
||||
info: 2,
|
||||
http: 3,
|
||||
verbose: 4,
|
||||
debug: 5,
|
||||
silly: 6
|
||||
};*/
|
||||
// const levels = {
|
||||
// error: 0,
|
||||
// warn: 1,
|
||||
// info: 2,
|
||||
// http: 3,
|
||||
// verbose: 4,
|
||||
// debug: 5,
|
||||
// silly: 6
|
||||
// };
|
@ -1,56 +0,0 @@
|
||||
const Transport = require('winston-transport');
|
||||
const moment = require('moment');
|
||||
const chalk = require('chalk');
|
||||
|
||||
const Constants = {
|
||||
Colors: {
|
||||
error: 'red',
|
||||
warn: 'yellow',
|
||||
info: 'blue',
|
||||
verbose: 'cyan',
|
||||
debug: 'magenta',
|
||||
silly: 'magentaBright'
|
||||
}
|
||||
};
|
||||
|
||||
class ExtendedConsole 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);
|
||||
});
|
||||
|
||||
//console.log('Extended console:');
|
||||
//console.log(info);
|
||||
|
||||
const hdr = info.message.match(/^(\[[0-9\-: ]{19}\](\[shard-[0-9]{2}\])?)/);
|
||||
if(hdr) info.message = info.message.replace(hdr[1], '').trim();
|
||||
|
||||
const color = Constants.Colors[info.level];
|
||||
const header = `${chalk[color](hdr ? hdr[1] : `[${this.date}]`)}`;
|
||||
|
||||
console.log(`${header} ${info.message}`);
|
||||
|
||||
if (callback) {
|
||||
callback(); // eslint-disable-line callback-return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
get date() {
|
||||
return moment().format("MM-DD-YYYY hh:mm:ss");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = ExtendedConsole;
|
118
middleware/logger/transports/FileExtension.js
Normal file
118
middleware/logger/transports/FileExtension.js
Normal file
@ -0,0 +1,118 @@
|
||||
const { transports: { File }} = require('winston');
|
||||
const debug = require('diagnostics')('winston:file');
|
||||
const { MESSAGE } = require('triple-beam');
|
||||
const moment = require('moment');
|
||||
const chalk = require('chalk');
|
||||
|
||||
const regex = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g
|
||||
|
||||
class FileExtension extends File {
|
||||
|
||||
constructor(opts) {
|
||||
super(opts);
|
||||
}
|
||||
|
||||
log(info, callback = () => {}) {
|
||||
// Remark: (jcrugzz) What is necessary about this callback(null, true) now
|
||||
// when thinking about 3.x? Should silent be handled in the base
|
||||
// TransportStream _write method?
|
||||
if (this.silent) {
|
||||
callback();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Output stream buffer is full and has asked us to wait for the drain event
|
||||
if (this._drain) {
|
||||
this._stream.once('drain', () => {
|
||||
this._drain = false;
|
||||
this.log(info, callback);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (this._rotate) {
|
||||
this._stream.once('rotate', () => {
|
||||
this._rotate = false;
|
||||
this.log(info, callback);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Grab the raw string and append the expected EOL.
|
||||
const output = `${info[MESSAGE]}${this.eol}`.replace(regex, '')
|
||||
const bytes = Buffer.byteLength(output);
|
||||
|
||||
// After we have written to the PassThrough check to see if we need
|
||||
// to rotate to the next file.
|
||||
//
|
||||
// Remark: This gets called too early and does not depict when data
|
||||
// has been actually flushed to disk.
|
||||
function logged() {
|
||||
this._size += bytes;
|
||||
this._pendingSize -= bytes;
|
||||
|
||||
debug('logged %s %s', this._size, output);
|
||||
this.emit('logged', info);
|
||||
|
||||
// Do not attempt to rotate files while opening
|
||||
if (this._opening) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check to see if we need to end the stream and create a new one.
|
||||
if (!this._needsNewFile()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// End the current stream, ensure it flushes and create a new one.
|
||||
// This could potentially be optimized to not run a stat call but its
|
||||
// the safest way since we are supporting `maxFiles`.
|
||||
this._rotate = true;
|
||||
this._endStream(() => this._rotateFile());
|
||||
}
|
||||
|
||||
// Keep track of the pending bytes being written while files are opening
|
||||
// in order to properly rotate the PassThrough this._stream when the file
|
||||
// eventually does open.
|
||||
this._pendingSize += bytes;
|
||||
if (this._opening
|
||||
&& !this.rotatedWhileOpening
|
||||
&& this._needsNewFile(this._size + this._pendingSize)) {
|
||||
this.rotatedWhileOpening = true;
|
||||
}
|
||||
|
||||
const written = this._stream.write(output, logged.bind(this));
|
||||
if (!written) {
|
||||
this._drain = true;
|
||||
this._stream.once('drain', () => {
|
||||
this._drain = false;
|
||||
callback();
|
||||
});
|
||||
} else {
|
||||
callback(); // eslint-disable-line callback-return
|
||||
}
|
||||
|
||||
debug('written', written, this._drain);
|
||||
|
||||
this.finishIfEnding();
|
||||
|
||||
return written;
|
||||
}
|
||||
|
||||
get date() {
|
||||
return moment().format("MM-DD-YYYY hh:mm:ss");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = FileExtension;
|
||||
|
||||
const Constants = {
|
||||
Colors: {
|
||||
error: 'red',
|
||||
warn: 'yellow',
|
||||
info: 'blue',
|
||||
verbose: 'cyan',
|
||||
debug: 'magenta',
|
||||
silly: 'magentaBright'
|
||||
}
|
||||
};
|
@ -1,5 +1,5 @@
|
||||
/* eslint-disable linebreak-style */
|
||||
module.exports = {
|
||||
DiscordWebhook: require('./DiscordWebhook.js'),
|
||||
ExtendedConsole: require('./ExtendedConsole.js')
|
||||
FileExtension: require('./FileExtension.js')
|
||||
};
|
@ -32,8 +32,6 @@ class DiscordClient extends Client {
|
||||
|
||||
if(this._built) return undefined;
|
||||
|
||||
console.log('Building Discord client');
|
||||
|
||||
await super.login(this._options.bot.token);
|
||||
|
||||
await this.registry.loadComponents('components/commands/', Command);
|
||||
@ -43,12 +41,6 @@ class DiscordClient extends Client {
|
||||
|
||||
this._built = true;
|
||||
|
||||
this.on('ready', () => {
|
||||
console.log('Client websocket is ready.');
|
||||
});
|
||||
|
||||
console.log('Client built');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -7,7 +7,8 @@ class Logger {
|
||||
this.client = client;
|
||||
|
||||
this.client.eventHooker.hook('ready', () => {
|
||||
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'}`)}.`);
|
||||
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 }) => {
|
||||
|
Loading…
Reference in New Issue
Block a user