mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-27 02:46:58 -05:00
Fix remaining console logs and types
This commit is contained in:
@@ -340,25 +340,84 @@ logger.error('Payment failed', {
|
||||
|
||||
---
|
||||
|
||||
## Summary
|
||||
## Edge Function Logging
|
||||
|
||||
✅ **Use `handleError()` for all application errors** - Logs to Admin Panel
|
||||
✅ **Use `logger.*` for non-error logging** - Structured and filterable
|
||||
✅ **Provide rich context with every log** - Makes debugging easier
|
||||
✅ **Use appropriate log levels (debug/info/warn/error)** - Environment-aware
|
||||
✅ **Let ESLint catch violations early** - No console statements allowed
|
||||
❌ **Never log sensitive data (passwords, tokens, PII)** - Security critical
|
||||
✅ **Re-throw errors after handleError()** - Let parent error boundaries catch them
|
||||
### Using `edgeLogger` in Edge Functions
|
||||
|
||||
Edge functions use the `edgeLogger` utility from `_shared/logger.ts`:
|
||||
|
||||
```typescript
|
||||
import { edgeLogger, startRequest, endRequest } from "../_shared/logger.ts";
|
||||
|
||||
const handler = async (req: Request): Promise<Response> => {
|
||||
const tracking = startRequest('function-name');
|
||||
|
||||
try {
|
||||
edgeLogger.info('Processing request', {
|
||||
requestId: tracking.requestId,
|
||||
// ... context
|
||||
});
|
||||
|
||||
// ... your code
|
||||
|
||||
const duration = endRequest(tracking);
|
||||
edgeLogger.info('Request completed', { requestId: tracking.requestId, duration });
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
const duration = endRequest(tracking);
|
||||
edgeLogger.error('Request failed', {
|
||||
error: errorMessage,
|
||||
requestId: tracking.requestId,
|
||||
duration
|
||||
});
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
### Logger Methods for Edge Functions
|
||||
- `edgeLogger.info()` - General information logging
|
||||
- `edgeLogger.warn()` - Warning conditions
|
||||
- `edgeLogger.error()` - Error conditions
|
||||
- `edgeLogger.debug()` - Detailed debugging (dev only)
|
||||
|
||||
All logs are visible in the Supabase Edge Function Logs dashboard.
|
||||
|
||||
**CRITICAL**: Never use `console.*` in edge functions. Always use `edgeLogger.*` instead.
|
||||
|
||||
---
|
||||
|
||||
## Summary
|
||||
|
||||
**Use `handleError()` for application errors** → Logs to Admin Panel + user-friendly toast
|
||||
**Use `logger.*` for general logging (client-side)** → Environment-aware console output
|
||||
**Use `edgeLogger.*` for edge function logging** → Structured logs visible in Supabase dashboard
|
||||
**Never use `console.*`** → Blocked by ESLint
|
||||
|
||||
This approach ensures:
|
||||
- ✅ Production builds are clean (no console noise)
|
||||
- ✅ All errors are tracked and actionable in Admin Panel
|
||||
- ✅ Users get helpful error messages with reference IDs
|
||||
- ✅ Development remains productive with detailed logs
|
||||
- ✅ Edge functions have structured, searchable logs
|
||||
|
||||
## Admin Panel Error Monitoring
|
||||
|
||||
All errors logged via `handleError()` are visible in the Admin Panel:
|
||||
- **URL**: `/admin/error-monitoring`
|
||||
- **Features**: Search by user, action, date, error type
|
||||
- **Reference IDs**: Each error has a unique ID shown to users
|
||||
- **Context**: Full metadata and breadcrumbs for debugging
|
||||
All errors logged via `handleError()` are visible in the Admin Panel at:
|
||||
|
||||
**Path**: `/admin/error-monitoring`
|
||||
|
||||
**Features**:
|
||||
- Search and filter errors by action, user, date range
|
||||
- View error context (metadata, breadcrumbs, environment)
|
||||
- Track error frequency and patterns
|
||||
- One-click copy of error details for debugging
|
||||
|
||||
**Access**: Admin role required
|
||||
|
||||
---
|
||||
|
||||
**Updated**: 2025-11-03
|
||||
**Status**: ✅ Enforced via ESLint (Frontend + Edge Functions)
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user