feat: Add centralized logging system with @link-stack/logger package

- Create new @link-stack/logger package wrapping Pino for structured logging
- Replace all console.log/error/warn statements across the monorepo
- Configure environment-aware logging (pretty-print in dev, JSON in prod)
- Add automatic redaction of sensitive fields (passwords, tokens, etc.)
- Remove dead commented-out logger file from bridge-worker
- Follow Pino's standard argument order (context object first, message second)
- Support log levels via LOG_LEVEL environment variable
- Export TypeScript types for better IDE support

This provides consistent, structured logging across all applications
and packages, making debugging easier and production logs more parseable.
This commit is contained in:
Darren Clarke 2025-08-20 11:37:39 +02:00
parent 5b89bfce7c
commit c1feaa4cb1
42 changed files with 3824 additions and 2422 deletions

View file

@ -1,4 +1,7 @@
import { db } from "@link-stack/bridge-common";
import { createLogger } from "@link-stack/logger";
const logger = createLogger('notify-webhooks');
export interface NotifyWebhooksOptions {
backendId: string;
@ -10,11 +13,10 @@ const notifyWebhooksTask = async (
): Promise<void> => {
const { backendId, payload } = options;
console.log(`[notify-webhooks] Processing webhook notification:`, {
logger.debug({
backendId,
payloadKeys: Object.keys(payload),
payload: JSON.stringify(payload, null, 2),
});
}, 'Processing webhook notification');
const webhooks = await db
.selectFrom("Webhook")
@ -22,20 +24,19 @@ const notifyWebhooksTask = async (
.where("backendId", "=", backendId)
.execute();
console.log(`[notify-webhooks] Found ${webhooks.length} webhooks for backend ${backendId}`);
logger.debug({ count: webhooks.length, backendId }, 'Found webhooks');
for (const webhook of webhooks) {
const { endpointUrl, httpMethod, headers } = webhook;
const finalHeaders = { "Content-Type": "application/json", ...headers };
const body = JSON.stringify(payload);
console.log(`[notify-webhooks] Sending webhook:`, {
logger.debug({
url: endpointUrl,
method: httpMethod,
bodyLength: body.length,
headers: Object.keys(finalHeaders),
payload: body,
});
headerKeys: Object.keys(finalHeaders),
}, 'Sending webhook');
try {
const result = await fetch(endpointUrl, {
@ -44,26 +45,26 @@ const notifyWebhooksTask = async (
body,
});
console.log(`[notify-webhooks] Webhook response:`, {
logger.debug({
url: endpointUrl,
status: result.status,
statusText: result.statusText,
ok: result.ok,
});
}, 'Webhook response');
if (!result.ok) {
const responseText = await result.text();
console.error(`[notify-webhooks] Webhook error response:`, {
logger.error({
url: endpointUrl,
status: result.status,
response: responseText.substring(0, 500), // First 500 chars
});
responseSample: responseText.substring(0, 500),
}, 'Webhook error response');
}
} catch (error) {
console.error(`[notify-webhooks] Webhook request failed:`, {
logger.error({
url: endpointUrl,
error: error instanceof Error ? error.message : error,
});
}, 'Webhook request failed');
}
}
};