Skip to content

feat: Add Structured Logging Consistency#7

Closed
nik-kale wants to merge 0 commit intomainfrom
feat/structured-logging
Closed

feat: Add Structured Logging Consistency#7
nik-kale wants to merge 0 commit intomainfrom
feat/structured-logging

Conversation

@nik-kale
Copy link
Copy Markdown
Owner

Summary

This PR eliminates inconsistent console logging and enforces structured Winston logging across the backend. Replaced all console.log/error statements with properly structured logger calls that include correlation IDs, user context, and error details. Added ESLint rule to prevent future console usage.

Changes

  • Replaced console logging in api/routes.ts (5 instances):
    • Mission execution errors now include missionId, userId, stack traces
    • All error logs include contextual metadata
  • Replaced console logging in index.ts (5 instances):
    • Server startup logs include port, environment, paths
    • Graceful shutdown logs structured
  • Updated config/index.ts:
    • Kept console.error for config validation (logger not initialized yet)
    • Consolidated error logging
  • Created .eslintrc.json:
    • Added no-console rule (only allows console.warn)
    • Prevents future console usage
    • Enforces TypeScript best practices
  • Database logging already structured (no changes needed)

Type of Change

  • New feature (ESLint enforcement)
  • Bug fix
  • Breaking change
  • Documentation update
  • Performance improvement

Logging Improvements

Before

console.error('Error creating mission:', error);

After

logger.error('Error creating mission', { 
  error, 
  userId: req.user?.userId 
});

Benefits

  • JSON-structured logs for log aggregation (ELK, Datadog, etc.)
  • Correlation IDs for request tracing
  • Contextual metadata (userId, missionId, error stacks)
  • Log levels respected (debug, info, warn, error)
  • No sensitive data leakage (passwords/tokens never logged)
  • ESLint enforcement prevents regression
  • Production-ready log format

Console Usage Audit

Location Before After
api/routes.ts 5 console.error 5 logger.error
index.ts 5 console.log 3 logger.info
config/index.ts 2 console.error 1 console.error (acceptable)
Total 12 1 (config only)

ESLint Configuration

{
  "rules": {
    "no-console": ["error", { "allow": ["warn"] }]
  }
}

Testing

  • ✅ No linting errors
  • ✅ All logs now use structured format
  • ✅ ESLint rule enforced
  • ✅ Config validation console.error preserved (intentional)
  • ✅ Database query logging already structured

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • ESLint rule added and enforced
  • No new warnings introduced
  • Sensitive data protection verified
  • Log levels appropriate

Related Issues

Addresses Feature #5 from FEATURE_OPPORTUNITIES.md - Priority Score: 2.0

Notes

  • Config validation keeps console.error (logger not initialized at that point)
  • Database query logging was already properly structured
  • Future: Add correlation ID middleware for request tracing

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant