Skip to content

[2026-02-07] Fix: Dev Logging Suppression in Production Builds

Task Metadata

  • 📆 Date: 2026-02-07
  • 🚥 Status: Complete
  • Beads Issue: (To be created)

Objective

Goal: Ensure diagnostic logs are visible in the Amplify dev deployment by making the logging level configurable via environment variables.

  • Trigger: Logs are currently missing in the Vite dev deployment because import.meta.env.PROD is true for all builds, causing logger.ts to default to warn level.
  • Constraints: Must not expose debug logs in the production environment (chatkcal.app).

Technical Strategy

Introduce a VITE_LOG_LEVEL environment variable that overrides the default production suppression.

  • Key Decisions:
    • Add VITE_LOG_LEVEL=debug to frontend/.env.dev.
    • Update frontend/src/utils/logger.ts to check import.meta.env.VITE_LOG_LEVEL before falling back to PROD logic.

Testing Strategy

  • Must Test: Verify logs appear in local development.
  • Skip: Manual verification on Amplify (requires deployment).

Risk Analysis

  • Potential Regressions: None.
  • Security Implications: Debug logs might leak non-sensitive metadata if incorrectly enabled in production.
  • Files to Modify:
    • frontend/.env.dev
    • frontend/src/utils/logger.ts
    • docs/architecture/testing_strategy.md (Update observability section)

1. Logger Configuration

Update the level selection logic.

// frontend/src/utils/logger.ts
const envLevel = import.meta.env.VITE_LOG_LEVEL;
if (envLevel) {
  log.setLevel(envLevel);
} else if (import.meta.env.PROD) {
  log.setLevel('warn');
} else {
  log.setLevel('debug');
}

Execution Plan

  • Step 1: Add VITE_LOG_LEVEL=debug to frontend/.env.dev.
  • Step 2: Update frontend/src/utils/logger.ts to respect the new environment variable.
  • Step 3: Update docs/architecture/testing_strategy.md to document the observability/logging configuration.
  • Verify: Check local console for [ChatKcal] prefixed debug logs.

Execution Notes

  • Implemented in frontend runtime/config:
    • frontend/.env.dev now sets VITE_LOG_LEVEL=debug.
    • frontend/src/utils/logger.ts now prioritizes VITE_LOG_LEVEL before import.meta.env.PROD fallback.
  • Documentation updated:
    • docs/architecture/testing_strategy.md now documents the observability/log-level control strategy.
  • Validation:
    • Verified debug-stage logs in usePromotion test output ([ChatKcal] stage transitions and outcomes).

User Approval & Key Learnings

Key Learnings

  • Production build mode (import.meta.env.PROD) is insufficient as a proxy for environment intent in multi-env deployments.
  • Explicit log-level env overrides are safer and easier to audit.

(User to confirm approval and add notes/learnings)

Context Memory (AI-Only)

Summary for Future Context

Fixing log suppression in dev builds by introducing VITE_LOG_LEVEL env var support in the frontend logger.