refactor(logging): replace remaining console statements with structured logger

- migrate.ts: console.log → logInfo
- seed.ts: console.log/logError → logInfo/logError
- CopyMeThatHtmlParser.ts/TxtParser.ts: console.error → logError
- index.ts: remove redundant console.error (already logged)

Aligns all server-side output with Winston logger conventions for consistency and observability.
This commit is contained in:
Paul Huliganga 2026-03-30 09:56:16 -04:00
parent b62b8061f7
commit 597e5c94c8
5 changed files with 11 additions and 9 deletions

View File

@ -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]}`) {

View File

@ -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);
});
}

View File

@ -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))) {

View File

@ -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;
}
}

View File

@ -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;
}
}