From 0e92359f8b6baf1d0e9b7ab13e571971c2e0c6ae Mon Sep 17 00:00:00 2001 From: Dawid Sowa Date: Tue, 7 Mar 2023 20:56:53 +0100 Subject: [PATCH] refactor: extract reusable logger instance --- src/chrome/chrome-connector-client.ts | 6 +----- src/pairing/pairing.tsx | 7 ++----- src/utils/logger.ts | 7 +++++++ 3 files changed, 10 insertions(+), 10 deletions(-) create mode 100644 src/utils/logger.ts diff --git a/src/chrome/chrome-connector-client.ts b/src/chrome/chrome-connector-client.ts index 79ffed25..f8ee1ca2 100644 --- a/src/chrome/chrome-connector-client.ts +++ b/src/chrome/chrome-connector-client.ts @@ -10,8 +10,8 @@ import { tap, } from 'rxjs' import { ChromeDAppClient } from './chrome-dapp-client' -import { Logger } from 'tslog' import { chromeLocalStore } from './helpers/chrome-local-store' +import { logger } from 'utils/logger' const chromeDAppClient = ChromeDAppClient() @@ -20,10 +20,6 @@ export const ChromeConnectorClient = () => { const subscriptions = new Subscription() const createConnector = () => { - const logger = new Logger({ - prettyLogTemplate: '{{hh}}:{{MM}}:{{ss}}:{{ms}}\t{{logLevelName}}\t', - minLevel: config.logLevel, - }) connector = ConnectorClient({ source: 'extension', target: 'wallet', diff --git a/src/pairing/pairing.tsx b/src/pairing/pairing.tsx index 7ed0f43c..3cc0249f 100644 --- a/src/pairing/pairing.tsx +++ b/src/pairing/pairing.tsx @@ -5,8 +5,8 @@ import { useEffect, useState } from 'react' import { chromeLocalStore } from 'chrome/helpers/chrome-local-store' import { ConnectorClient } from 'connector/connector-client' import { config } from 'config' -import { Logger } from 'tslog' import { ok } from 'neverthrow' +import { logger } from 'utils/logger' export const Paring = () => { const [pairingState, setPairingState] = useState< @@ -22,10 +22,7 @@ export const Paring = () => { target: 'wallet', signalingServerBaseUrl: config.signalingServer.baseUrl, isInitiator: config.webRTC.isInitiator, - logger: new Logger({ - prettyLogTemplate: '{{hh}}:{{MM}}:{{ss}}:{{ms}}\t{{logLevelName}}\t', - minLevel: config.logLevel, - }), + logger, }) chrome.storage.onChanged.addListener((changes, area) => { diff --git a/src/utils/logger.ts b/src/utils/logger.ts new file mode 100644 index 00000000..4c01056a --- /dev/null +++ b/src/utils/logger.ts @@ -0,0 +1,7 @@ +import { config } from 'config' +import { Logger } from 'tslog' + +export const logger = new Logger({ + prettyLogTemplate: '{{hh}}:{{MM}}:{{ss}}:{{ms}}\t{{logLevelName}}\t', + minLevel: config.logLevel, +})