Skip to content

Conversation

@smartlabsAT
Copy link
Owner

Summary

  • Replace all direct console.error calls with structured logger system
  • Eliminate console usage violations while maintaining functionality
  • Add comprehensive logger utility with environment-aware logging
  • Improve debugging with structured data instead of string concatenation

Changes Made

🚀 New Logger Utility (src/utils/logger.ts)

Features:

  • TypeScript Interface: Fully typed Logger with debug/info/warn/error levels
  • Environment-aware: Respects NODE_ENV (production vs development vs test)
  • Structured Logging: Supports structured data objects for better debugging
  • Context-aware: All logs include BreakpointProvider context prefix

Behavior:

  • Production: Only error-level logs are output
  • Development/Test: All log levels are output
  • Consistent format: [BreakpointProvider] message with structured data

🔧 BreakpointContext Updates

Before: Direct console.error calls with concatenated strings

console.error('❌ BreakpointProvider: Duplicate breakpoint values detected...');

After: Structured logger calls with meaningful data

logger.error('Duplicate breakpoint values detected', {
  duplicates: duplicates.map(([key, value]) => ({ key, value })),
  message: 'This may lead to unexpected behavior'
});

🧹 Replaced Console Calls

  1. Duplicate breakpoint detection → Structured error with duplicate details
  2. Width validation errors → Structured error with width values
  3. Breakpoint determination errors → Structured error with configuration context

Benefits

  • Code Quality: Eliminates all direct console usage violations
  • Better Debugging: Structured data instead of concatenated strings
  • Environment Control: Proper production vs development logging behavior
  • Maintainability: Centralized logging logic with TypeScript interfaces
  • Performance: Reduced logging overhead in production
  • Backward Compatibility: Maintains existing shouldLog functionality

Quality Checks

  • ✅ All tests pass (17/17) including new logger tests
  • ✅ ESLint validation passed
  • ✅ TypeScript compilation successful
  • ✅ 100% test coverage for logger utility
  • ✅ Pre-commit hooks passed (lint, typecheck, build, test)

Test Coverage

  • Logger utility: 100% coverage across all methods and environments
  • Environment scenarios: production, development, and test modes
  • Structured data: Complex objects and nested data logging
  • Integration tests: Updated BreakpointContext tests for new format

Test plan

  • All existing functionality preserved through test suite
  • Logger behavior verified across different NODE_ENV values
  • Structured data logging validated with complex objects
  • No console usage violations remain in codebase
  • Production logging limited to errors only
  • Development logging includes all levels with proper formatting

Fixes #5

- Create logger utility with TypeScript interfaces and environment-aware logging
- Replace all console.error calls with structured logger.error calls
- Add comprehensive logger tests with environment mode coverage
- Use structured data instead of string concatenation for better debugging
- Maintain existing devMode functionality while eliminating console violations
- Logger respects NODE_ENV: only errors in production, all levels in development

Features:
- Environment-aware logging (production vs development vs test)
- Structured data support for better debugging context
- Full TypeScript typing with Logger interface
- 100% test coverage for logger utility
- Maintains backward compatibility with shouldLog parameter

Fixes #5
@smartlabsAT smartlabsAT merged commit c837042 into main Oct 6, 2025
3 checks passed
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.

Replace direct console usage with proper logging system

2 participants