diff --git a/src/modules/fetch/index.ts b/src/modules/fetch/index.ts index e82baea..ed14420 100644 --- a/src/modules/fetch/index.ts +++ b/src/modules/fetch/index.ts @@ -1,6 +1,8 @@ import originalFetch from 'isomorphic-unfetch'; -import { logger } from '../logger'; +import { baseLogger } from '../logger'; + +const logger = baseLogger.extend('fetch'); export const fetch = async ( url: Parameters[0], @@ -17,7 +19,7 @@ export const fetch = async ( }, }; - logger(`Will call "%s" with %O`, url, options); + logger('Will call "%s" with: %j', url, options); const result = await originalFetch(url, options); const response = await (async () => { diff --git a/src/modules/generic-create/index.ts b/src/modules/generic-create/index.ts index 8c60c6c..4ba1749 100644 --- a/src/modules/generic-create/index.ts +++ b/src/modules/generic-create/index.ts @@ -1,13 +1,16 @@ +import { Big } from 'big.js'; + import { getBridgeFor } from '../context'; import { fetch } from '../fetch'; -import { logger } from '../logger'; +import { baseLogger } from '../logger'; import { SkybridgeMode } from '../modes'; import { SkybridgeParams } from '../common-params'; import { runProofOfWork } from '../pow'; import { SkybridgeResource } from '../resources'; import { getChainFor } from '../chains'; import { SkybridgeCoin } from '../coins'; -import { Big } from 'big.js'; + +const logger = baseLogger.extend('generic-create'); export type CreateParams = { resource: R; @@ -57,7 +60,7 @@ const createRec = async ({ timeout, ...params }: CreateParams & { startedAt: number; timeout: number }): Promise> => { - logger('Will execute create(%O).', { ...params, resource, startedAt, timeout }); + logger('Will execute create(%j).', { ...params, resource, startedAt, timeout }); const bridge = getBridgeFor(params); await (async () => { @@ -111,7 +114,7 @@ const createRec = async ({ }, ); - logger(`/${apiPathResource}/create has replied: %O`, result); + logger('/%s/create has replied: %j', apiPathResource, result); if (result.ok) { return { diff --git a/src/modules/logger/index.ts b/src/modules/logger/index.ts index 3c162e7..4d261da 100644 --- a/src/modules/logger/index.ts +++ b/src/modules/logger/index.ts @@ -1,3 +1,3 @@ import debug from 'debug'; -export const logger = debug('skybridge-sdk'); +export const baseLogger = debug('skybridge-sdk'); diff --git a/src/modules/pow/getBlockHeight/index.ts b/src/modules/pow/getBlockHeight/index.ts index 4690a8c..fc0e7fa 100644 --- a/src/modules/pow/getBlockHeight/index.ts +++ b/src/modules/pow/getBlockHeight/index.ts @@ -1,10 +1,12 @@ import type { SkybridgeBridge } from '../../bridges'; import { fetch } from '../../fetch'; -import { logger } from '../../logger'; +import { baseLogger } from '../../logger'; import type { SkybridgeMode } from '../../modes'; import type { SkybridgeParams } from '../../common-params'; import type { SkybridgeResource } from '../../resources'; +const logger = baseLogger.extend('block-height'); + const TIMEOUT = 1 * 60 * 1000; const INTERVAL = 2000; diff --git a/src/modules/swap/createSwap/index.ts b/src/modules/swap/createSwap/index.ts index 2ebb32f..ae63b14 100644 --- a/src/modules/swap/createSwap/index.ts +++ b/src/modules/swap/createSwap/index.ts @@ -1,8 +1,10 @@ import type { SkybridgeMode } from '../../modes'; import { create, CreateParams, CreateResult } from '../../generic-create'; -import { logger } from '../../logger'; +import { baseLogger } from '../../logger'; import { fetch } from '../../fetch'; +const logger = baseLogger.extend('create-swap'); + export const createSwap = async ( params: Omit, 'resource'> & { affiliateCode?: string | null }, ): Promise> => { @@ -32,7 +34,7 @@ export const createSwap = async ( throw new Error(`Affiliate code linking failed: ${linkResult.response}`); } - logger('Swap linked to affiliate code: %O', linkResult.response); + logger('Swap linked to affiliate code: %j', linkResult.response); } catch (e) { logger('Failed calling the affiliate program API: %s', e.message); } diff --git a/src/modules/validate-address/isBinanceAddress.ts b/src/modules/validate-address/isBinanceAddress.ts index b744d78..a4a328b 100644 --- a/src/modules/validate-address/isBinanceAddress.ts +++ b/src/modules/validate-address/isBinanceAddress.ts @@ -1,7 +1,9 @@ import { decode, fromWords } from 'bech32'; import type { SkybridgeContext } from '../context'; -import { logger } from '../logger'; +import { baseLogger } from '../logger'; + +const logger = baseLogger.extend('address-binance'); export const isBinanceAddress = ({ context,