Merge pull request #139 from samuelthomas2774/add-object-logging
Add object logging handler
This commit is contained in:
commit
d1d2610416
|
@ -24,6 +24,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));
|
||||
}
|
||||
|
|
|
@ -173,7 +173,7 @@ export default class {
|
|||
|
||||
const configs = {
|
||||
defaultConfig: readConfig.defaultConfig,
|
||||
schemes: readConfig.configSchemes,
|
||||
schemes: readConfig.configSchemes,
|
||||
userConfig
|
||||
}
|
||||
|
||||
|
|
|
@ -123,16 +123,16 @@
|
|||
}
|
||||
|
||||
.bd-settings .bd-sidebar-view.bd-stop .bd-content-region {
|
||||
z-index: 3003;
|
||||
z-index: 3003;
|
||||
}
|
||||
|
||||
.bd-backdrop {
|
||||
z-index: 3003;
|
||||
z-index: 3003;
|
||||
}
|
||||
|
||||
.bd-sidebar .bd-settings-button {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
top: 0;
|
||||
|
||||
.platform-darwin & {
|
||||
top: 22px;
|
||||
|
|
|
@ -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) {
|
||||
|
@ -46,26 +46,26 @@ export class Utils {
|
|||
return camelCased;
|
||||
}
|
||||
|
||||
static compare(value1, value2) {
|
||||
// Check to see if value1 and value2 contain the same data
|
||||
if (typeof value1 !== typeof value2) return false;
|
||||
if (value1 === null && value2 === null) return true;
|
||||
if (value1 === null || value2 === null) return false;
|
||||
static compare(value1, value2) {
|
||||
// Check to see if value1 and value2 contain the same data
|
||||
if (typeof value1 !== typeof value2) return false;
|
||||
if (value1 === null && value2 === null) return true;
|
||||
if (value1 === null || value2 === null) return false;
|
||||
|
||||
if (typeof value1 === 'object' || typeof value1 === 'array') {
|
||||
// Loop through the object and check if everything's the same
|
||||
let value1array = typeof value1 === 'array' ? value1 : Object.keys(value1);
|
||||
let value2array = typeof value2 === 'array' ? value2 : Object.keys(value2);
|
||||
if (value1array.length !== value2array.length) return false;
|
||||
if (typeof value1 === 'object' || typeof value1 === 'array') {
|
||||
// Loop through the object and check if everything's the same
|
||||
let value1array = typeof value1 === 'array' ? value1 : Object.keys(value1);
|
||||
let value2array = typeof value2 === 'array' ? value2 : Object.keys(value2);
|
||||
if (value1array.length !== value2array.length) return false;
|
||||
|
||||
for (let key in value1) {
|
||||
if (!this.compare(value1[key], value2[key])) return false;
|
||||
}
|
||||
} else if (value1 !== value2) return false;
|
||||
for (let key in value1) {
|
||||
if (!this.compare(value1[key], value2[key])) return false;
|
||||
}
|
||||
} else if (value1 !== value2) return false;
|
||||
|
||||
// value1 and value2 contain the same data
|
||||
return true;
|
||||
}
|
||||
// value1 and value2 contain the same data
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export class FileUtils {
|
||||
|
@ -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';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ console.log(dummyArgs);
|
|||
class Comms {
|
||||
|
||||
constructor(bd) {
|
||||
this.bd = bd;
|
||||
this.bd = bd;
|
||||
this.initListeners();
|
||||
}
|
||||
|
||||
|
|
|
@ -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