Add object logging
This commit is contained in:
parent
b51e675291
commit
78a61dc60f
|
@ -23,6 +23,8 @@ class BetterDiscord {
|
|||
window.wpm = WebpackModules;
|
||||
window.bdsettings = Settings;
|
||||
window.bdmodals = Modals;
|
||||
window.bdlogs = Logger;
|
||||
|
||||
DOM.injectStyle(BdCss, 'bdmain');
|
||||
Events.on('global-ready', this.globalReady.bind(this));
|
||||
}
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
export { ClientIPC } from './bdipc';
|
||||
export * from './utils';
|
||||
export * from './utils';
|
||||
export { ClientLogger } from './logger';
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/**
|
||||
* BetterDiscord Logger Module
|
||||
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
|
||||
* All rights reserved.
|
||||
* https://betterdiscord.net
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import { Vendor } from 'modules';
|
||||
|
||||
const logs = [];
|
||||
|
||||
export class ClientLogger {
|
||||
|
||||
static err(module, message) { this.log(module, message, 'err'); }
|
||||
static warn(module, message) { this.log(module, message, 'warn'); }
|
||||
static info(module, message) { this.log(module, message, 'info'); }
|
||||
static dbg(module, message) { this.log(module, message, 'dbg'); }
|
||||
|
||||
static log(module, message, level = 'log') {
|
||||
level = this.parseLevel(level);
|
||||
if (typeof message === 'object' && !(message instanceof Array)) {
|
||||
console[level]('[%cBetter%cDiscord:%s]', 'color: #3E82E5', '', `${module}${level === 'debug' ? '|DBG' : ''}`, message);
|
||||
let message_string = message.toString();
|
||||
if (message_string === '[object Object]')
|
||||
message_string += ' ' + JSON.stringify(message, null, 4);
|
||||
|
||||
logs.push(`${level.toUpperCase()} : [${Vendor.moment().format('DD/MM/YY hh:mm:ss')}|${module}] ${message_string}${message_string === '[object Object]' ? ' ' + JSON.stringify(message, null, 4) : ''}`);
|
||||
return;
|
||||
}
|
||||
|
||||
message = typeof message === 'object' && message instanceof Array ? message : [message];
|
||||
console[level]('[%cBetter%cDiscord:%s]', 'color: #3E82E5', '', `${module}${level === 'debug' ? '|DBG' : ''}`, ...message);
|
||||
logs.push(`${level.toUpperCase()} : [${Vendor.moment().format('DD/MM/YY hh:mm:ss')}|${module}] ${message.join(' ')}`);
|
||||
}
|
||||
|
||||
static logError(err) {
|
||||
if (!err.module && !err.message) {
|
||||
console.log(err);
|
||||
return;
|
||||
}
|
||||
this.err(err.module, err.message);
|
||||
}
|
||||
|
||||
static get logs() {
|
||||
return logs;
|
||||
}
|
||||
|
||||
static get levels() {
|
||||
return {
|
||||
'log': 'log',
|
||||
'warn': 'warn',
|
||||
'err': 'error',
|
||||
'error': 'error',
|
||||
'debug': 'debug',
|
||||
'dbg': 'debug',
|
||||
'info': 'info'
|
||||
};
|
||||
}
|
||||
|
||||
static parseLevel(level) {
|
||||
return this.levels.hasOwnProperty(level) ? this.levels[level] : 'log';
|
||||
}
|
||||
|
||||
}
|
|
@ -13,7 +13,7 @@ const
|
|||
fs = require('fs'),
|
||||
_ = require('lodash');
|
||||
|
||||
import { Vendor } from 'modules';
|
||||
import { Vendor } from 'modules';
|
||||
|
||||
export class Utils {
|
||||
static overload(fn, cb) {
|
||||
|
@ -197,48 +197,3 @@ export class FileUtils {
|
|||
return this.listDirectory(path);
|
||||
}
|
||||
}
|
||||
|
||||
const logs = [];
|
||||
|
||||
export class ClientLogger {
|
||||
static err(module, message) { this.log(module, message, 'err'); }
|
||||
static warn(module, message) { this.log(module, message, 'warn'); }
|
||||
static info(module, message) { this.log(module, message, 'info'); }
|
||||
static dbg(module, message) { this.log(module, message, 'dbg'); }
|
||||
static log(module, message, level = 'log') {
|
||||
message = message.message || message;
|
||||
if (typeof message === 'object') {
|
||||
//TODO object handler for logs
|
||||
console.log(message);
|
||||
return;
|
||||
}
|
||||
level = this.parseLevel(level);
|
||||
console[level]('[%cBetter%cDiscord:%s] %s', 'color: #3E82E5', '', `${module}${level === 'debug' ? '|DBG' : ''}`, message);
|
||||
logs.push(`${level.toUpperCase()} : [${Vendor.moment().format('DD/MM/YY hh:mm:ss')}|${module}] ${message}`);
|
||||
window.bdlogs = logs;
|
||||
}
|
||||
|
||||
static logError(err) {
|
||||
if (!err.module && !err.message) {
|
||||
console.log(err);
|
||||
return;
|
||||
}
|
||||
this.err(err.module, err.message);
|
||||
}
|
||||
|
||||
static get levels() {
|
||||
return {
|
||||
'log': 'log',
|
||||
'warn': 'warn',
|
||||
'err': 'error',
|
||||
'error': 'error',
|
||||
'debug': 'debug',
|
||||
'dbg': 'debug',
|
||||
'info': 'info'
|
||||
};
|
||||
}
|
||||
|
||||
static parseLevel(level) {
|
||||
return this.levels.hasOwnProperty(level) ? this.levels[level] : 'log';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,8 +34,8 @@
|
|||
console.info(`[BetterDiscord|WebSocket Proxy] WebSocket stored to __bd['wsHook']`);
|
||||
window.__bd.wsHook = this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
window.WebSocket = WSHook;
|
||||
})();
|
||||
})();
|
||||
|
|
Loading…
Reference in New Issue