Skip to content

feat: add structured API request/response logging middleware#436

Merged
Baskarayelu merged 1 commit into
Remitwise-Org:mainfrom
1sraeliteX:feat/logging-middleware
May 29, 2026
Merged

feat: add structured API request/response logging middleware#436
Baskarayelu merged 1 commit into
Remitwise-Org:mainfrom
1sraeliteX:feat/logging-middleware

Conversation

@1sraeliteX
Copy link
Copy Markdown
Contributor

  • Add sanitization utilities (lib/sanitize.ts) for redacting sensitive data
  • Add structured JSON logging (lib/logger.ts) for all /api/* routes
  • Add request ID generation and tracking (lib/requestId.ts)
  • Add comprehensive test suite (tests/unit/sanitize.test.ts) with 31 tests
  • Add complete documentation (docs/logging.md)
  • Integrate logging into middleware.ts with request/response tracking
  • Add LOG_LEVEL configuration to .env.example

Features:

  • Never logs request bodies to prevent sensitive data exposure
  • Automatically sanitizes response data before logging
  • Redacts sensitive fields: password, token, apiKey, privateKey, etc.
  • Partially masks: email (us***@), wallet addresses (GBXXXX)
  • Configurable log levels: debug, info, warn, error
  • Request ID tracking across logs via X-Request-ID header
  • Recursion depth limit (5 levels) to prevent infinite loops
  • Case-insensitive field matching for sensitive fields

All tests passing (31/31 sanitize tests + existing tests) TypeScript compilation: zero errors
Build: successful

- Add sanitization utilities (lib/sanitize.ts) for redacting sensitive data
- Add structured JSON logging (lib/logger.ts) for all /api/* routes
- Add request ID generation and tracking (lib/requestId.ts)
- Add comprehensive test suite (tests/unit/sanitize.test.ts) with 31 tests
- Add complete documentation (docs/logging.md)
- Integrate logging into middleware.ts with request/response tracking
- Add LOG_LEVEL configuration to .env.example

Features:
- Never logs request bodies to prevent sensitive data exposure
- Automatically sanitizes response data before logging
- Redacts sensitive fields: password, token, apiKey, privateKey, etc.
- Partially masks: email (us***@***), wallet addresses (GBXXXX***)
- Configurable log levels: debug, info, warn, error
- Request ID tracking across logs via X-Request-ID header
- Recursion depth limit (5 levels) to prevent infinite loops
- Case-insensitive field matching for sensitive fields

All tests passing (31/31 sanitize tests + existing tests)
TypeScript compilation: zero errors
Build: successful
@1sraeliteX
Copy link
Copy Markdown
Contributor Author

@maintainer check and merge my PR!

@Baskarayelu
Copy link
Copy Markdown
Contributor

link the issue

@Baskarayelu Baskarayelu merged commit 61a9e2d into Remitwise-Org:main May 29, 2026
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.

2 participants