From 2709a61eaa5f030475a7373ab37d4b0b1cee71a8 Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Mon, 19 Aug 2024 09:48:53 +0200 Subject: [PATCH] Clean up log level usage --- README.md | 2 +- src/lib/DataProviderManager.ts | 21 ++++++++++++--------- src/lib/util.ts | 2 +- src/providers/bitcoind.ts | 10 +++++----- src/providers/esplora.ts | 2 +- src/providers/mempool.ts | 2 +- src/server.tsx | 8 +++++--- 7 files changed, 26 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index b8b0fb8..5afed06 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ Here are the available configuration options: | `settings.feeMultiplier` | The multiplier to apply to the fee estimates | `1` | `FEE_MULTIPLIER` | | `settings.feeMinimum` | The minimum fee (sat/vB) to use for fee estimates if we could not determine from a configured data source | `2` | `FEE_MINIMUM` | | `settings.maxHeightDelta` | The maximum acceptable difference between the block heights of the most current fee estimates. | `3` | `MAX_HEIGHT_DELTA` | -| `cache.stdTTL` | The standard time to live in seconds for every generated cache element | `15` | `CACHE_STD_TTL` | +| `cache.stdTTL` | The standard time to live in seconds for every generated cache element | `15` | `CACHE_STD_TTL` | | `cache.checkperiod` | The period in seconds, used for the automatic delete check interval | `20` | `CACHE_CHECKPERIOD` | ### Mempool settings diff --git a/src/lib/DataProviderManager.ts b/src/lib/DataProviderManager.ts index 7b05ddc..17911f8 100644 --- a/src/lib/DataProviderManager.ts +++ b/src/lib/DataProviderManager.ts @@ -104,9 +104,9 @@ export class DataProviderManager { feeEstimates, } as DataPoint; } catch (error) { - console.error( - `Error fetching data from provider ${p.constructor.name}: ${error}`, - ); + log.error({ + message: `Error fetching data from provider ${p.constructor.name}: ${error}`, + }); return null; } }), @@ -161,8 +161,8 @@ export class DataProviderManager { dataPoints[0].blockHeight - dp.blockHeight <= this.maxHeightDelta; if (!isRelevant) { - console.warn({ - msg: `Data point from block ${dp.blockHeight} was filtered out due to relevancy threshold.`, + log.warn({ + message: `Data point from block ${dp.blockHeight} was filtered out due to relevancy threshold.`, }); } @@ -181,7 +181,7 @@ export class DataProviderManager { Object.entries(feeEstimates).filter(([blockTarget, estimate]) => { if (estimate < this.feeMinimum) { log.warn({ - msg: `Fee estimate for target ${blockTarget} was below the minimum of ${this.feeMinimum}.`, + message: `Fee estimate for target ${blockTarget} was below the minimum of ${this.feeMinimum}.`, }); return false; } @@ -206,7 +206,10 @@ export class DataProviderManager { const keys = Object.keys(estimates) .map(Number) .sort((a, b) => a - b); - log.debug({ msg: `Estimates for dataPoint ${providerName}`, estimates }); + log.debug({ + message: `Estimates for dataPoint ${providerName}`, + estimates, + }); keys.forEach((key) => { // Only add the estimate if it has a higher confirmation target and a lower fee. @@ -216,14 +219,14 @@ export class DataProviderManager { estimates[key] < Math.min(...Object.values(mergedEstimates))) ) { log.debug({ - msg: `Adding estimate from ${providerName} with target ${key} and fee ${estimates[key]} to mergedEstimates`, + message: `Adding estimate from ${providerName} with target ${key} and fee ${estimates[key]} to mergedEstimates`, }); mergedEstimates[key] = estimates[key]; } }); } - log.debug({ msg: "Final mergedEstimates:", mergedEstimates }); + log.debug({ message: "Final mergedEstimates:", mergedEstimates }); return mergedEstimates; } } diff --git a/src/lib/util.ts b/src/lib/util.ts index cec2566..a7de158 100644 --- a/src/lib/util.ts +++ b/src/lib/util.ts @@ -63,7 +63,7 @@ export async function fetchData( : response.text()); return data as T; } catch (error) { - log.error({ msg: `Error fetching data from "${url}":`, error }); + log.warn({ message: `Error fetching data from "${url}":`, error }); throw error; } } diff --git a/src/providers/bitcoind.ts b/src/providers/bitcoind.ts index e738b10..7e0b307 100644 --- a/src/providers/bitcoind.ts +++ b/src/providers/bitcoind.ts @@ -44,7 +44,7 @@ export class BitcoindProvider implements Provider { const getBlockCount = promisify(this.rpc.getBlockCount.bind(this.rpc)); const response = await getBlockCount(); - log.trace({ msg: "getBlockCount", response: response.result }); + log.trace({ message: "getBlockCount", response: response.result }); return response.result; } @@ -60,7 +60,7 @@ export class BitcoindProvider implements Provider { ); const response = await getBestBlockHash(); - log.trace({ msg: "getBestBlockHash", response: response.result }); + log.trace({ message: "getBestBlockHash", response: response.result }); return response.result; } @@ -76,7 +76,7 @@ export class BitcoindProvider implements Provider { ); const response = await estimateSmartFee(target, this.mode); - log.trace({ msg: "estimateSmartFee", response: response.result }); + log.trace({ message: "estimateSmartFee", response: response.result }); return response.result?.feerate; } @@ -116,14 +116,14 @@ export class BitcoindProvider implements Provider { } catch (error) { errorCount++; log.warn({ - msg: `Error getting fee estimate for target ${target}:`, + message: `Error getting fee estimate for target ${target}:`, errors: responses[i].result?.errors.join(", "), }); } }); if (errorCount === this.targets.length) { - log.error({ msg: "Error getting fee estimates" }); + log.error({ message: "Error getting fee estimates" }); throw new Error("Error getting fee estimates"); } diff --git a/src/providers/esplora.ts b/src/providers/esplora.ts index b017f16..90c2037 100644 --- a/src/providers/esplora.ts +++ b/src/providers/esplora.ts @@ -121,7 +121,7 @@ export class EsploraProvider implements Provider { feeEstimates, }; } catch (error) { - log.error({ msg: "Error fetching all data from Esplora:", error }); + log.error({ message: "Error fetching all data from Esplora:", error }); throw error; } } diff --git a/src/providers/mempool.ts b/src/providers/mempool.ts index 57ecff6..45d5d62 100644 --- a/src/providers/mempool.ts +++ b/src/providers/mempool.ts @@ -122,7 +122,7 @@ export class MempoolProvider implements Provider { feeEstimates, }; } catch (error) { - log.error({ msg: "Error fetching all data from Mempool:", error }); + log.error({ message: "Error fetching all data from Mempool:", error }); throw error; } } diff --git a/src/server.tsx b/src/server.tsx index d9753d6..b60b9f0 100644 --- a/src/server.tsx +++ b/src/server.tsx @@ -42,7 +42,7 @@ const CACHE_CHECKPERIOD = config.get("cache.checkperiod"); const log = logger(LOGLEVEL, "server"); const middlewareLogger = (message: string, ...rest: string[]) => { - log.info({ msg: message, ...rest }); + log.info({ message, ...rest }); }; // Log the configuration values. @@ -95,8 +95,10 @@ ESPLORA_FALLBACK_BASE_URL && // Initialize the Express app. const app = new Hono(); -log.info({ msg: `Fee Estimates available at ${BASE_URL}/v1/fee-estimates` }); -log.info({ msg: `Website available at ${BASE_URL}` }); +log.info({ + message: `Fee Estimates available at ${BASE_URL}/v1/fee-estimates`, +}); +log.info({ message: `Website available at ${BASE_URL}` }); // Add a health/ready endpoint. app.get("/health/ready", async (c) => {