Create BxLogger to show colored logs

This commit is contained in:
redphx
2024-04-30 18:52:56 +07:00
parent 26c318fb8d
commit edc8991a6a
9 changed files with 59 additions and 15 deletions

27
src/utils/bx-logger.ts Normal file
View File

@@ -0,0 +1,27 @@
enum TextColor {
INFO = '#008746',
WARNING = '#c1a404',
ERROR = '#c10404',
}
export class BxLogger {
static #PREFIX = '[BxC]';
static info(tag: string, ...args: any[]) {
BxLogger.#log(TextColor.INFO, tag, ...args);
}
static warning(tag: string, ...args: any[]) {
BxLogger.#log(TextColor.WARNING, tag, ...args);
}
static error(tag: string, ...args: any[]) {
BxLogger.#log(TextColor.ERROR, tag, ...args);
}
static #log(color: TextColor, tag: string, ...args: any) {
console.log('%c' + BxLogger.#PREFIX, 'color:' + color + ';font-weight:bold;', tag, '-', ...args);
}
}
(window as any).BxLogger = BxLogger;

View File

@@ -2,6 +2,7 @@ import { MkbHandler } from "../modules/mkb/mkb-handler";
import { PrefKey, getPref } from "./preferences";
import { t } from "./translation";
import { Toast } from "./toast";
import { BxLogger } from "./bx-logger";
// Show a toast when connecting/disconecting controller
export function showGamepadToast(gamepad: Gamepad) {
@@ -10,7 +11,7 @@ export function showGamepadToast(gamepad: Gamepad) {
return;
}
console.log(gamepad);
BxLogger.info('Gamepad', gamepad);
let text = '🎮';
if (getPref(PrefKey.LOCAL_CO_OP_ENABLED)) {

View File

@@ -2,6 +2,7 @@ import { BxEvent } from "./bx-event";
import { getPref, PrefKey } from "./preferences";
import { STATES } from "./global";
import { UserAgent } from "./user-agent";
import { BxLogger } from "./bx-logger";
export function patchVideoApi() {
const PREF_SKIP_SPLASH_VIDEO = getPref(PrefKey.SKIP_SPLASH_VIDEO);
@@ -77,7 +78,7 @@ export function patchRtcCodecs() {
nativeSetCodecPreferences.apply(this, [newCodecs]);
} catch (e) {
// Didn't work -> use default codecs
console.log(e);
BxLogger.error('setCodecPreferences', e);
nativeSetCodecPreferences.apply(this, [codecs]);
}
}
@@ -106,7 +107,8 @@ export function patchRtcPeerConnection() {
if (conn.connectionState === 'connecting') {
STATES.currentStream.audioGainNode = null;
}
console.log('connectionState', conn.connectionState);
BxLogger.info('connectionstatechange', conn.connectionState);
});
return conn;
}