[Feature]: Implement Unified Debug Logging System with Centralized Log Aggregation #80
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem / User Need
As a developer and operator, I need a unified logging system that:
LOG_LEVELenvironment variable set in CI/CDdocs/UX-DEBUGGING.mdCurrently, enabling debug logging requires manually modifying
vite.config.tsTerser/ESBuild options and rebuilding. There is no unified log level control, no correlation IDs, and no centralized log aggregation.Proposed Solution
Implement a unified logging system with:
LOG_LEVEL(DEBUG, INFO, WARN, ERROR) set in CI/CDscripts/ci/generate-log-config.shmaps single variable to per-container settingsArchitecture
Unified LOG_LEVEL Mapping
Non-goals / Out of Scope
Acceptance Criteria (Feature Behavior)
Research Tasks
X-Request-IdConfig Generator (
scripts/ci/generate-log-config.sh)LOG_LEVELinput (DEBUG, INFO, WARN, ERROR).env.loggingwith all mapped variablesFrontend
VITE_LOG_LEVELrequestIdin API call logs for correlationBackend
LOG_LEVELfrom environmentX-Request-Idmissing)OCR Container
LOG_LEVELfrom environmentjobIdgeneration for long-running jobsrequestIdfrom triggering requestPostgreSQL
Redis
loglevelfromREDIS_LOGLEVELenvironment variableTraefik
X-Request-Idheader generation/forwardingTRAEFIK_LOG_LEVELInfrastructure (docker-compose.yml)
CI/CD
generate-log-config.sh DEBUGgenerate-log-config.sh INFO.env.loggingbeforedocker-compose upDocumentation
docs/UX-DEBUGGING.mdwith new logging systemIntegration Criteria (App Flow)
Navigation
Routing
https://logs.motovaultpro.comor:3000)State Management
Visual Integration (Design Consistency)
N/A - This is an infrastructure/backend feature. Grafana provides its own UI.
Implementation Notes
Current State
docs/UX-DEBUGGING.mddocuments manual Vite config modification processfrontend/vite.config.tshas Terserdrop_console: trueand ESBuilddrop: ['console']Files to Create/Modify
scripts/ci/generate-log-config.shfrontend/src/utils/logger.tsconfig/promtail/config.ymlconfig/loki/config.ymldocker-compose.yml(add 3 containers, add logging config to all)frontend/vite.config.ts(respect VITE_LOG_LEVEL)docs/UX-DEBUGGING.md.gitea/workflows/staging.yaml.gitea/workflows/production.yamlContainer Count Change
Before: 5 containers (Traefik, Frontend, Backend, PostgreSQL, Redis)
After: 8 containers (+ Promtail, Loki, Grafana)
Correlation ID Reference
requestIdjobIduserIdvehicleIdTest Plan
Unit tests:
Integration tests:
Manual testing:
Plan: Unified Debug Logging System
Phase: Planning | Agent: Orchestrator | Status: IN_PROGRESS
Codebase Analysis Summary
Current State Findings:
logger.ts, hardcodedlevel: 'info'console.logcalls, no centralized loggerKey Gap: Issue assumes Pino, but backend uses Winston (79 files).
Architectural Decision: Winston vs Pino
Decision-Critic Verdict: REVISE - Migrate to Pino
Decision: Migrate to Pino using a wrapper pattern in
logger.tsthat maintains API compatibility. This allows:Sub-Issue Breakdown
This feature is too large for a single AI context. Breaking into 7 smaller issues:
scripts/ci/generate-log-config.shbackend/src/core/logging/, pluginsconfig/traefik/frontend/src/utils/logger.tsdocker-compose.ymllogging blocksImplementation Plan
Milestone 1: Foundation (Sub-issues #80-A, #80-C, #80-E)
Parallel execution possible
#80-A: Config Generator Script
scripts/ci/generate-log-config.sh.env.loggingwith per-container mappings#80-C: Traefik X-Request-Id
x-request-idmiddleware toconfig/traefik/dynamic/middleware.yml#80-E: Docker Logging Configuration
logging:block to all 6 services in docker-compose.ymlMilestone 2: Backend Logging (Sub-issue #80-B)
Depends on #80-A
#80-B: Pino Migration + Correlation IDs
Files to modify:
backend/src/core/logging/logger.ts- Replace Winston with Pino wrapperbackend/src/core/plugins/logging.plugin.ts- Use @fastify/pinobackend/package.json- Add pino, @fastify/pino; remove winstonImplementation:
Correlation ID middleware:
Acceptance:
Milestone 3: Frontend Logging (Sub-issue #80-D)
Depends on #80-A
#80-D: Frontend Logger Module
Create
frontend/src/utils/logger.ts:Modify
frontend/vite.config.ts:Update API client to include requestId in logs for correlation.
Acceptance:
Milestone 4: Log Aggregation Stack (Sub-issue #80-F)
Depends on #80-E
#80-F: Promtail + Loki + Grafana
Add to docker-compose.yml:
mvp-promtail: Scrapes Docker logs, forwards to Lokimvp-loki: Log storage with 30-day retentionmvp-grafana: Visualization with Loki datasourceCreate configs:
config/promtail/config.yml- Docker log scrapingconfig/loki/config.yml- Storage, retention, indexContainer count: 6 → 9
Acceptance:
Milestone 5: CI/CD + Documentation (Sub-issue #80-G)
Depends on all above
#80-G: CI/CD Integration
Modify workflows:
.gitea/workflows/staging.yaml: Rungenerate-log-config.sh DEBUG.gitea/workflows/production.yaml: Rungenerate-log-config.sh INFO.env.loggingbefore docker-compose upUpdate documentation:
docs/UX-DEBUGGING.mdwith new logging system docsAcceptance:
Quality Gates
Test Plan
Unit Tests:
Integration Tests:
Manual Tests:
Verdict: AWAITING_REVIEW | Next: QR plan-completeness review
TW Review: Plan Revisions
Phase: Plan-Review | Agent: Technical Writer | Status: COMPLETE
Following QR plan-completeness review, the following additions are incorporated:
Revision A: Environment Defaults
Revision B: Loki Failure Behavior
Failure Resilience:
Revision C: Implementation Risks
logger.info(msg, meta)API; regression testingRevision D: Container Count Clarification
Current: 6 application containers (Traefik, Frontend, Backend, OCR, PostgreSQL, Redis)
After: 9 total (6 application + 3 logging: Promtail, Loki, Grafana)
Note: Logging containers optional for local development; mandatory for staging/production.
Revision E: PostgreSQL/Redis Assignment
Added to Sub-issue #80-B acceptance criteria:
PostgreSQL Logging:
Redis Logging:
Verdict: REVISIONS_APPLIED | Next: QR plan-code review
Plan Review Cycle Complete
Phase: Plan-Review | Agent: Quality Reviewer | Status: COMPLETE
Review Summary
Outstanding Items Addressed
QR plan-docs concerns resolved:
Container Count Clarification:
UX-DEBUGGING.md Scope:
Documentation Acceptance Criteria (clarified):
requestId(UUID v4)https://logs.motovaultpro.comor internal:3000QR plan-code Fixes (incorporated into implementation)
Final Plan Verdict
APPROVED FOR EXECUTION
All concerns have been addressed or have clear resolution paths during implementation. The plan is complete with:
Next Steps
issue-80-unified-loggingVerdict: PLAN_APPROVED | Next: Create sub-issues and begin execution
Planning Complete - Sub-Issues Created
Phase: Planning | Agent: Orchestrator | Status: COMPLETE
Sub-Issue Summary
Execution Order
Key Architectural Decisions
Winston → Pino Migration: Approved via decision-critic. Wrapper pattern maintains API compatibility for 79 importing files.
Container Architecture: 6 → 9 containers (adding Promtail, Loki, Grafana)
Correlation Strategy: X-Request-Id generated by backend if not present from Traefik, propagated via AsyncLocalStorage
Next Steps
status/readyfor Milestone 1issue-80-unified-loggingVerdict: PLANNING_COMPLETE | Next: Execution
Completion Summary
All sub-issues have been implemented and merged to main:
Delivered Capabilities
LOG_LEVELenvironment variable controls all servicesrequestId) flow through Traefik -> Backend -> logsQuality Checks
Documentation
docs/LOGGING.md- Complete logging system documentationdocs/UX-DEBUGGING.md- Deleted (replaced by LOGGING.md)Verdict: PASS | All acceptance criteria met via sub-issues