Logging
1 min readRapid overview
Logging for Frontend and Node.js
Use these notes to explain how you design low-overhead logging pipelines for client and server environments.
Principles
- Structured logs: Prefer JSON with consistent keys.
- Contextual logging: Include
requestId,userId, and feature flags. - Redaction: Remove PII and secrets before shipping logs.
Frontend logging
- Log UI errors via
window.onerrorandunhandledrejection. - Sample high-volume logs to control cost.
- Batch logs before sending to a backend collector.
window.addEventListener('error', (event) => {
logger.error('ui_error', { message: event.message, stack: event.error?.stack });
});
Node.js logging
- Use middleware to attach request context.
- Log at boundaries (incoming request, upstream call, DB call).
- Keep logs consistent across services.
app.use((req, _res, next) => {
req.id = crypto.randomUUID();
next();
});
Log levels
- debug: Dev-only details.
- info: Normal operations.
- warn: Unexpected but recoverable.
- error: Failures that need attention.
Interview prompts
- How do you correlate client logs with server traces?
- When should you sample logs?
- How do you prevent logging sensitive data?