diff --git a/apps/browser-extension-wallet/package.json b/apps/browser-extension-wallet/package.json index c504d2e6e..d6e4cc58f 100644 --- a/apps/browser-extension-wallet/package.json +++ b/apps/browser-extension-wallet/package.json @@ -117,6 +117,7 @@ "fork-ts-checker-webpack-plugin": "^7.2.1", "jest-webextension-mock": "^3.9.0", "text-encoding-utf-8": "^1.0.2", + "ts-log": "^2.2.7", "tsconfig-paths-webpack-plugin": "3.5.2", "webassembly-loader-sw": "^1.1.0" } diff --git a/apps/browser-extension-wallet/src/lib/scripts/background/stringifyLogger.ts b/apps/browser-extension-wallet/src/lib/scripts/background/stringifyLogger.ts new file mode 100644 index 000000000..2252898ae --- /dev/null +++ b/apps/browser-extension-wallet/src/lib/scripts/background/stringifyLogger.ts @@ -0,0 +1,38 @@ +/* eslint-disable no-console */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import { Logger } from 'ts-log'; +import { toSerializableObject } from '@cardano-sdk/util'; + +export class StringifyLogger implements Logger { + private convertParams(params: any[]) { + return params.map((param) => + param && typeof param === 'object' ? JSON.stringify(toSerializableObject(param)) : param + ); + } + + trace(...params: any[]): void { + console.trace(...this.convertParams(params)); + } + + debug(...params: any[]): void { + console.debug(...this.convertParams(params)); + } + + info(...params: any[]): void { + console.log(...this.convertParams(params)); + } + + warn(...params: any[]): void { + console.warn(...this.convertParams(params)); + } + + error(...params: any[]): void { + console.error(...this.convertParams(params)); + } + + fatal(...params: any[]): void { + console.error(...this.convertParams(params)); + } +} + +export const logger = new StringifyLogger(); diff --git a/apps/browser-extension-wallet/src/lib/scripts/background/wallet.ts b/apps/browser-extension-wallet/src/lib/scripts/background/wallet.ts index e1554f967..100bf6d61 100644 --- a/apps/browser-extension-wallet/src/lib/scripts/background/wallet.ts +++ b/apps/browser-extension-wallet/src/lib/scripts/background/wallet.ts @@ -32,8 +32,7 @@ import axiosFetchAdapter from '@shiroyasha9/axios-fetch-adapter'; import { SharedWalletScriptKind } from '@lace/core'; import { getBaseUrlForChain } from '@utils/chain'; import { cacheNamiMetadataSubscription } from './cache-nami-metadata'; - -const logger = console; +import { logger } from './stringifyLogger'; // It is important that this file is not exported from index, // because creating wallet repository with store creates an actual pouchdb database diff --git a/yarn.lock b/yarn.lock index df2c81caa..457d712a0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13265,6 +13265,7 @@ __metadata: readable-stream: ^3.6.0 rxjs: 7.4.0 text-encoding-utf-8: ^1.0.2 + ts-log: ^2.2.7 tsconfig-paths-webpack-plugin: 3.5.2 webassembly-loader-sw: ^1.1.0 webextension-polyfill: 0.10.0 @@ -56718,6 +56719,13 @@ __metadata: languageName: node linkType: hard +"ts-log@npm:^2.2.7": + version: 2.2.7 + resolution: "ts-log@npm:2.2.7" + checksum: c423a5eb54abb9471578902953814d3d0c88b3f237db016998f8998ecf982cb0f748bb8ebf93670eeba9b836ff0ce407d8065a340f3ab218ea7b9442c255b3d4 + languageName: node + linkType: hard + "ts-mixer@npm:^6.0.3": version: 6.0.4 resolution: "ts-mixer@npm:6.0.4"