Skip to content

Commit

Permalink
test: stringify objects in service worker console log
Browse files Browse the repository at this point in the history
  • Loading branch information
iccicci committed Oct 17, 2024
1 parent ac8887b commit bdc9926
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
1 change: 1 addition & 0 deletions apps/browser-extension-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit bdc9926

Please sign in to comment.