- Add express-rate-limit with tiered rate limits per endpoint - Add express-validator for input validation on all API routes - Add winston + morgan for structured logging - Add node-cache for lottery result caching (5min TTL, 1000 max keys) - Convert OCR to async task queue with max 2 concurrent jobs - Add global error handler middleware - Add React ErrorBoundary for client-side error handling - Fix memory leaks in OCR task queue and lottery cache - Add per-item error handling in batch ticket updates - Fix SQL UPDATE to include user_id in WHERE clause Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
27 lines
971 B
JavaScript
27 lines
971 B
JavaScript
const winston = require('winston');
|
|
const path = require('path');
|
|
|
|
const logger = winston.createLogger({
|
|
level: process.env.LOG_LEVEL || 'info',
|
|
format: winston.format.combine(
|
|
winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
|
|
winston.format.errors({ stack: true }),
|
|
winston.format.json()
|
|
),
|
|
defaultMeta: { service: 'lottery-api' },
|
|
transports: [
|
|
new winston.transports.File({ filename: path.join(__dirname, '../logs/error.log'), level: 'error' }),
|
|
new winston.transports.File({ filename: path.join(__dirname, '../logs/combined.log') }),
|
|
new winston.transports.Console({
|
|
format: winston.format.combine(
|
|
winston.format.colorize(),
|
|
winston.format.printf(({ timestamp, level, message, ...meta }) => {
|
|
const metaStr = Object.keys(meta).length ? JSON.stringify(meta) : '';
|
|
return `${timestamp} [${level}]: ${message} ${metaStr}`;
|
|
})
|
|
)
|
|
})
|
|
]
|
|
});
|
|
|
|
module.exports = logger; |