Merge branch 'staging' into cursor/add-migration-and-update-endpoint-1563

This commit is contained in:
dal 2025-07-03 15:32:02 -06:00
commit d405493b64
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
4 changed files with 34 additions and 59 deletions

View File

@ -36,7 +36,7 @@ RUN START=$(date +%s) && \
RUN START=$(date +%s) && \ RUN START=$(date +%s) && \
echo "=== Starting application build ===" && \ echo "=== Starting application build ===" && \
cd apps/server && \ cd apps/server && \
time bun build src/index.ts --outdir ./dist --target bun && \ time bun build src/index.ts --outdir ./dist --target bun --external pino-pretty && \
echo "Build complete - output:" && \ echo "Build complete - output:" && \
ls -la dist/ && \ ls -la dist/ && \
END=$(date +%s) && \ END=$(date +%s) && \

View File

@ -8,7 +8,7 @@
}, },
"scripts": { "scripts": {
"prebuild": "bun run scripts/validate-env.js", "prebuild": "bun run scripts/validate-env.js",
"build": "bun build src/index.ts --outdir ./dist --target bun", "build": "bun build src/index.ts --outdir ./dist --target bun --external pino-pretty",
"dev": "bun --max-old-space-size=512 run --hot src/index.ts", "dev": "bun --max-old-space-size=512 run --hot src/index.ts",
"lint": "biome check", "lint": "biome check",
"prod": "pnpm run build:vercel && pnpm run start:vercel", "prod": "pnpm run build:vercel && pnpm run start:vercel",

View File

@ -10,19 +10,7 @@ describe('logger middleware', () => {
debug: typeof console.debug; debug: typeof console.debug;
}; };
beforeEach(() => { import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
// Save original env and console
originalEnv = { ...process.env };
originalConsole = {
info: console.info,
warn: console.warn,
error: console.error,
debug: console.debug,
};
// Clear module cache to reload logger with new env
vi.resetModules();
});
afterEach(() => { afterEach(() => {
// Restore original env and console // Restore original env and console

View File

@ -1,34 +1,40 @@
import { pinoLogger } from 'hono-pino'; import { pinoLogger } from 'hono-pino';
import pino from 'pino'; import pino from 'pino';
import 'pino-pretty';
const isDev = process.env.NODE_ENV !== 'production'; const isDev = process.env.NODE_ENV !== 'production';
const logLevel = process.env.LOG_LEVEL || 'info'; const logLevel = process.env.LOG_LEVEL || 'info';
let isPinoPrettyAvailable = true; // Create base pino instance
const createBaseLogger = () => {
// Create base pino instance for console capture if (isDev) {
const baseLogger = pino({ try {
// Only use pino-pretty transport in development
return pino({
level: logLevel, level: logLevel,
transport: isDev && isPinoPrettyAvailable transport: {
? {
target: 'pino-pretty', target: 'pino-pretty',
options: { colorize: true }, options: { colorize: true },
} },
: undefined,
}); });
} catch (error) {
console.warn('pino-pretty not available, falling back to JSON logging');
console.error(error);
}
}
// Production or fallback: use standard JSON logging
return pino({
level: logLevel,
});
};
const baseLogger = createBaseLogger();
// Simple console capture - only override if LOG_LEVEL is set // Simple console capture - only override if LOG_LEVEL is set
if (process.env.LOG_LEVEL) { if (process.env.LOG_LEVEL) {
const originalConsole = { console.info = (...args) => baseLogger.info(...args);
info: console.info, console.warn = (...args) => baseLogger.warn(...args);
warn: console.warn, console.error = (...args) => baseLogger.error(...args);
error: console.error,
};
console.info = (...args) => baseLogger.info(args.join(' '));
console.warn = (...args) => baseLogger.warn(args.join(' '));
console.error = (...args) => baseLogger.error(args.join(' '));
// Suppress debug logs when LOG_LEVEL is info or higher // Suppress debug logs when LOG_LEVEL is info or higher
if (logLevel !== 'debug' && logLevel !== 'trace') { if (logLevel !== 'debug' && logLevel !== 'trace') {
@ -36,26 +42,7 @@ if (process.env.LOG_LEVEL) {
} }
} }
// Create logger with fallback for pino-pretty failures // Create logger middleware
function createLogger() { export const loggerMiddleware = pinoLogger({
// Try pino-pretty in development
if (isDev && isPinoPrettyAvailable) {
try {
return pinoLogger({
pino: baseLogger, pino: baseLogger,
}); });
} catch (error) {
console.error('pino-pretty not available, falling back to JSON logging', error);
isPinoPrettyAvailable = false;
}
}
// Fallback to simple JSON logging
return pinoLogger({
pino: {
level: logLevel,
},
});
}
export const loggerMiddleware = createLogger();