Skip to content

Commit

Permalink
test: stringify objects in service worker console log (#1471)
Browse files Browse the repository at this point in the history
  • Loading branch information
iccicci authored Oct 18, 2024
1 parent ac8887b commit 8c22ff5
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
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 '@lace/common';

// It is important that this file is not exported from index,
// because creating wallet repository with store creates an actual pouchdb database
Expand Down
1 change: 1 addition & 0 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"react-tooltip": "4.2.7"
},
"devDependencies": {
"ts-log": "^2.2.7",
"typescript": "^4.9.5"
},
"peerDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ export * from '@ui/components/Radio';
export * from '@ui/components/Timeline';

export * from '@analytics/index';

export * from './stringifyLogger';
38 changes: 38 additions & 0 deletions packages/common/src/stringifyLogger.ts
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();
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13331,6 +13331,7 @@ __metadata:
react-copy-to-clipboard: 5.0.4
react-dom: 17.0.2
react-tooltip: 4.2.7
ts-log: ^2.2.7
typescript: ^4.9.5
peerDependencies:
react: 17.0.2
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 8c22ff5

Please sign in to comment.