1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-07-06 02:58:31 +00:00
FrankerFaceZ/src/utilities/logging.js
SirStendec d6504757b3 4.0.0-rc13.11
* Added: Debug Log generation and easy uploading for issue reports.
* Fixed: Bug with chat lines not having a state causing rendering to crash.
* Fixed: Add an error boundary around the custom FFZ Emote Menu to catch errors, displaying feedback and sending error reports rather than silently failing.
* Fixed: Typo in Fine when logging errors.
* Changed: Update chat types with the latest values from Twitch's source.
* Changed: Update the GitHub issue template with instructions on uploading logs from v4.
2018-12-03 18:08:32 -05:00

119 lines
No EOL
2.3 KiB
JavaScript

'use strict';
const RAVEN_LEVELS = {
1: 'debug',
2: 'info',
4: 'warn',
8: 'error'
};
export default class Logger {
constructor(parent, name, level, raven) {
this.root = parent ? parent.root : this;
this.parent = parent;
this.name = name;
if ( this.root == this )
this.captured_init = [];
this.init = false;
this.enabled = true;
this.level = level || (parent && parent.level) || Logger.DEFAULT_LEVEL;
this.raven = raven || (parent && parent.raven);
this.children = {};
}
get(name, level) {
if ( ! this.children[name] )
this.children[name] = new Logger(this, (this.name ? `${this.name}.${name}` : name), level);
return this.children[name];
}
debug(...args) {
return this.invoke(Logger.DEBUG, args);
}
info(...args) {
return this.invoke(Logger.INFO, args);
}
warn(...args) {
return this.invoke(Logger.WARN, args);
}
error(...args) {
return this.invoke(Logger.ERROR, args);
}
crumb(...args) {
if ( this.raven )
return this.raven.captureBreadcrumb(...args);
}
capture(exc, opts, ...args) {
if ( this.raven ) {
opts = opts || {};
if ( ! opts.logger )
opts.logger = this.name;
this.raven.captureException(exc, opts);
}
if ( args.length )
return this.error(...args);
}
/* eslint no-console: "off" */
invoke(level, args) {
if ( ! this.enabled || level < this.level )
return;
const message = Array.prototype.slice.call(args);
if ( this.root.init )
this.root.captured_init.push({
time: Date.now(),
category: this.name,
message: message.join(' '),
level: RAVEN_LEVELS[level] || level
});
this.crumb({
message: message.join(' '),
category: this.name,
level: RAVEN_LEVELS[level] || level
});
if ( this.name )
message.unshift(`%cFFZ [%c${this.name}%c]:%c`, 'color:#755000; font-weight:bold', '', 'color:#755000; font-weight:bold', '');
else
message.unshift('%cFFZ:%c', 'color:#755000; font-weight:bold', '');
if ( level === Logger.DEBUG )
console.info(...message);
else if ( level === Logger.INFO )
console.info(...message);
else if ( level === Logger.WARN )
console.warn(...message);
else if ( level === Logger.ERROR )
console.error(...message);
else
console.log(...message);
}
}
Logger.DEFAULT_LEVEL = 2;
Logger.DEBUG = 1;
Logger.INFO = 2;
Logger.WARN = 4;
Logger.ERROR = 8;
Logger.OFF = 99;