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

@ -3,6 +3,9 @@ import Google from "next-auth/providers/google";
import Apple from "next-auth/providers/apple";
import Credentials from "next-auth/providers/credentials";
import { checkAuth } from "./opensearch";
import { createLogger } from "@link-stack/logger";
const logger = createLogger('leafcutter-auth');
export const authOptions: NextAuthOptions = {
pages: {
@ -45,7 +48,7 @@ export const authOptions: NextAuthOptions = {
return user;
} catch (e) {
console.error({ e });
logger.error({ e });
}
return null;

View file

@ -1,6 +1,9 @@
/* eslint-disable no-underscore-dangle */
import { Client } from "@opensearch-project/opensearch";
import { v4 as uuid } from "uuid";
import { createLogger } from "@link-stack/logger";
const logger = createLogger('leafcutter-opensearch');
/* Common */
@ -302,7 +305,7 @@ export const updateUserVisualization = async (
body,
});
} catch (e) {
console.error({ e });
logger.error({ e });
}
return id;

View file

@ -4,6 +4,9 @@ import { Client } from "@opensearch-project/opensearch";
import { v4 as uuid } from "uuid";
import taxonomy from "app/_config/taxonomy.json";
import unRegions from "app/_config/unRegions.json";
import { createLogger } from "@link-stack/logger";
const logger = createLogger('leafcutter-index');
export const POST = async (req: NextRequest) => {
const { tickets } = await req.json();
@ -46,7 +49,7 @@ export const POST = async (req: NextRequest) => {
});
succeeded.push(id);
} catch (e) {
console.error(e);
logger.error(e);
failed.push(id);
}
}

View file

@ -18,6 +18,7 @@
"@emotion/server": "^11.11.0",
"@emotion/styled": "^11.14.0",
"@link-stack/leafcutter-ui": "*",
"@link-stack/logger": "*",
"@link-stack/opensearch-common": "*",
"@mui/icons-material": "^6",
"@mui/material": "^6",

View file

@ -1,6 +1,9 @@
import { createProxyMiddleware } from "http-proxy-middleware";
import { NextApiRequest, NextApiResponse } from "next";
import { getToken } from "next-auth/jwt";
import { createLogger } from "@link-stack/logger";
const logger = createLogger('leafcutter-[[...path]]');
/*
@ -30,11 +33,11 @@ const withAuthInfo =
);
if (requestSignature && isAppPath) {
console.info("Has Signature");
logger.info("Has Signature");
}
if (referrerSignature && isResourcePath) {
console.info("Has Signature");
logger.info("Has Signature");
}
if (!email) {