diff --git a/src/backend/db/migrate.ts b/src/backend/db/migrate.ts index 46ce54a..cd8c632 100644 --- a/src/backend/db/migrate.ts +++ b/src/backend/db/migrate.ts @@ -2,6 +2,7 @@ import initSqlJs from 'sql.js'; import fs from 'fs'; import path from 'path'; import { applyRuntimeMigrations } from './schemaMigrations.js'; +import { logInfo } from '../logger.js'; const DATA_DIR = path.resolve(process.cwd(), 'data'); const DB_PATH = path.join(DATA_DIR, 'recipes.db'); @@ -10,7 +11,7 @@ const SCHEMA_PATH = path.resolve(process.cwd(), 'src/backend/db/schema.sql'); async function ensureDataDir() { if (!fs.existsSync(DATA_DIR)) { fs.mkdirSync(DATA_DIR, { recursive: true }); - console.log(`Created data directory at ${DATA_DIR}`); + logInfo(`Created data directory at ${DATA_DIR}`); } } @@ -33,7 +34,7 @@ async function applyMigrations() { const data = db.export(); fs.writeFileSync(DB_PATH, Buffer.from(data)); db.close(); - console.log(`Database migrated: ${DB_PATH}`); + logInfo(`Database migrated: ${DB_PATH}`); } if (import.meta.url === `file://${process.argv[1]}`) { diff --git a/src/backend/db/seed.ts b/src/backend/db/seed.ts index 50eccda..baccdf2 100644 --- a/src/backend/db/seed.ts +++ b/src/backend/db/seed.ts @@ -2,6 +2,7 @@ import initSqlJs from 'sql.js'; import fs from 'fs'; import path from 'path'; import { applyRuntimeMigrations } from './schemaMigrations.js'; +import { logInfo, logError } from '../logger.js'; interface SeedIngredient { quantity?: string; @@ -484,12 +485,12 @@ async function seedDatabase() { fs.writeFileSync(DB_PATH, Buffer.from(data)); db.close(); - console.log(`Seed complete. Created ${createdCount}, updated ${updatedCount}, total seed recipes ${seedRecipes.length}.`); + logInfo(`Seed complete. Created ${createdCount}, updated ${updatedCount}, total seed recipes ${seedRecipes.length}.`); } if (import.meta.url === `file://${process.argv[1]}`) { seedDatabase().catch((error) => { - console.error('Seed failed:', error); + logError('Seed failed:', error); process.exit(1); }); } diff --git a/src/backend/index.ts b/src/backend/index.ts index 8f2d919..ddbea6e 100644 --- a/src/backend/index.ts +++ b/src/backend/index.ts @@ -132,7 +132,6 @@ async function startServer() { // Global error handler app.use((err: any, req: express.Request, res: express.Response, next: express.NextFunction) => { logError('Unhandled error:', err); - console.error('Error type:', err.constructor?.name, 'Stack:', err.stack); // Zod validation errors → 400 if (err.constructor?.name === 'ZodError' || (err.errors && Array.isArray(err.errors))) { diff --git a/src/backend/services/CopyMeThatHtmlParser.ts b/src/backend/services/CopyMeThatHtmlParser.ts index 651bce6..f076db6 100644 --- a/src/backend/services/CopyMeThatHtmlParser.ts +++ b/src/backend/services/CopyMeThatHtmlParser.ts @@ -1,5 +1,5 @@ import type { CreateRecipeInput } from '../types/recipe.js'; -import { logDebug } from '../logger.js'; +import { logDebug, logError } from '../logger.js'; export interface ParsedCopyMeThatRecipe { title: string; @@ -69,7 +69,7 @@ export class CopyMeThatHtmlParser { const notes = this.extractNotes(html); if (!title || ingredients.length === 0 || instructions.length === 0) { - console.log(`[Parser] Rejected recipe - title: ${!!title}, ingredients: ${ingredients.length}, instructions: ${instructions.length}`); + logDebug(`[Parser] Rejected recipe - title: ${!!title}, ingredients: ${ingredients.length}, instructions: ${instructions.length}`); return null; // Invalid recipe } @@ -87,7 +87,7 @@ export class CopyMeThatHtmlParser { notes: notes ? this.cleanText(notes) : undefined, }; } catch (error) { - console.error('Error parsing recipe block:', error); + logError('Error parsing recipe block:', error); return null; } } diff --git a/src/backend/services/CopyMeThatTxtParser.ts b/src/backend/services/CopyMeThatTxtParser.ts index 3624ca3..04e5481 100644 --- a/src/backend/services/CopyMeThatTxtParser.ts +++ b/src/backend/services/CopyMeThatTxtParser.ts @@ -1,4 +1,5 @@ import type { CreateRecipeInput } from '../types/recipe.js'; +import { logError } from '../logger.js'; export interface ParsedCopyMeThatTxtRecipe { title: string; @@ -106,7 +107,7 @@ export class CopyMeThatTxtParser { notes, }; } catch (error) { - console.error('Error parsing TXT recipe:', error); + logError('Error parsing TXT recipe:', error); return null; } }