Skip to content

Commit

Permalink
fix: Minor improvements to logs
Browse files Browse the repository at this point in the history
  • Loading branch information
sbp-rib committed Jan 29, 2021
1 parent ef0b74d commit 3d6e9f6
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/modules/fetch/index.ts
Original file line number Diff line number Diff line change
@@ -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 <SuccessResponse extends unknown>(
url: Parameters<typeof originalFetch>[0],
Expand All @@ -17,7 +19,7 @@ export const fetch = async <SuccessResponse extends unknown>(
},
};

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 () => {
Expand Down
11 changes: 7 additions & 4 deletions src/modules/generic-create/index.ts
Original file line number Diff line number Diff line change
@@ -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<R extends SkybridgeResource, M extends SkybridgeMode> = {
resource: R;
Expand Down Expand Up @@ -57,7 +60,7 @@ const createRec = async <R extends SkybridgeResource, M extends SkybridgeMode>({
timeout,
...params
}: CreateParams<R, M> & { startedAt: number; timeout: number }): Promise<CreateResult<R, M>> => {
logger('Will execute create(%O).', { ...params, resource, startedAt, timeout });
logger('Will execute create(%j).', { ...params, resource, startedAt, timeout });
const bridge = getBridgeFor(params);

await (async () => {
Expand Down Expand Up @@ -111,7 +114,7 @@ const createRec = async <R extends SkybridgeResource, M extends SkybridgeMode>({
},
);

logger(`/${apiPathResource}/create has replied: %O`, result);
logger('/%s/create has replied: %j', apiPathResource, result);

if (result.ok) {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/logger/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import debug from 'debug';

export const logger = debug('skybridge-sdk');
export const baseLogger = debug('skybridge-sdk');
4 changes: 3 additions & 1 deletion src/modules/pow/getBlockHeight/index.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
6 changes: 4 additions & 2 deletions src/modules/swap/createSwap/index.ts
Original file line number Diff line number Diff line change
@@ -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 <M extends SkybridgeMode>(
params: Omit<CreateParams<'swap', M>, 'resource'> & { affiliateCode?: string | null },
): Promise<CreateResult<'swap', M>> => {
Expand Down Expand Up @@ -32,7 +34,7 @@ export const createSwap = async <M extends SkybridgeMode>(
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);
}
Expand Down
4 changes: 3 additions & 1 deletion src/modules/validate-address/isBinanceAddress.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit 3d6e9f6

Please sign in to comment.