Skip to content

Commit

Permalink
fix: mute debug log warnings (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
sidmorizon authored Dec 2, 2024
1 parent 37fa103 commit cdd9bee
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions packages/core/src/loggers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { IDebugLogger, ConsoleLike } from '@onekeyfe/cross-inpage-provider-types';
import { ConsoleLike, IDebugLogger } from '@onekeyfe/cross-inpage-provider-types';
// @ts-ignore
import createDebugAsync from './debug';
import { DEBUG_LOGGER_STORAGE_KEY } from './consts';
import { CrossEventEmitter } from './CrossEventEmitter';
import createDebugAsync from './debug';

// enable debugLogger:
// localStorage.setItem('$$ONEKEY_DEBUG_LOGGER', '*');
Expand Down Expand Up @@ -41,6 +41,7 @@ class FakeDebugLogger extends CrossEventEmitter implements IDebugLogger {
constructor() {
super();
this.initExternalLogInstances();
this.setMaxListeners(9999);
}

jsBridge = (...args: any[]) => null;
Expand All @@ -58,6 +59,8 @@ class FakeDebugLogger extends CrossEventEmitter implements IDebugLogger {
});
}

isFaked = true;

_debug = {
enable(config: string) {
//noop
Expand All @@ -80,12 +83,14 @@ class FakeDebugLogger extends CrossEventEmitter implements IDebugLogger {
(name: string) =>
(...args: any[]) => {
this.once('debugReady', () => {
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
this[name]?.(...args);
if (!this.isFaked) {
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
this[name]?.(...args);
}
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
return this._externalLogger?.log?.(`${name } >>> `, ...args);
return this._externalLogger?.log?.(`${name} >>> `, ...args);
};
}

Expand All @@ -95,11 +100,14 @@ class AppDebugLogger extends FakeDebugLogger {
// TODO createDebugSync
void createDebugAsync().then((debug) => {
this._debug = debug;
this.isFaked = false;
this.initDebugInstances();
this.emit('debugReady');
});
}

isFaked = false;

initDebugInstances() {
if (this.isDebugReady()) {
Object.keys(loggerNames).forEach((name) => {
Expand Down Expand Up @@ -142,4 +150,4 @@ class AppDebugLogger extends FakeDebugLogger {
const fakeDebugLogger: IDebugLogger = new FakeDebugLogger();
const appDebugLogger: IDebugLogger = new AppDebugLogger();

export { fakeDebugLogger, appDebugLogger, fakeLogger, consoleErrorInDev };
export { appDebugLogger, consoleErrorInDev, fakeDebugLogger, fakeLogger };

0 comments on commit cdd9bee

Please sign in to comment.