Skip to content

Commit

Permalink
Clean up log level usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfelton committed Aug 19, 2024
1 parent f767a7e commit 2709a61
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 12 additions & 9 deletions src/lib/DataProviderManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}),
Expand Down Expand Up @@ -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.`,
});
}

Expand All @@ -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;
}
Expand All @@ -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.
Expand All @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export async function fetchData<T>(
: 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;
}
}
10 changes: 5 additions & 5 deletions src/providers/bitcoind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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");
}

Expand Down
2 changes: 1 addition & 1 deletion src/providers/esplora.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/providers/mempool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const CACHE_CHECKPERIOD = config.get<number>("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.
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit 2709a61

Please sign in to comment.