feat: Add production logging gating (Phase 1, Task 1.1)

- Created logger utility with environment-based gating (lib/utils/logger.ts)
- Replaced 517 console.log statements with logger.log (71% reduction)
- Fixed import paths in 15 files (resolved comment-trapped imports)
- Added DEBUG_LOGS=false to .env
- Achieves 71% immediate log reduction (517/731 statements)
- Expected 90% reduction in production when deployed

Impact: Reduced I/O blocking, lower log volume in production
Risk: LOW (easy rollback, non-invasive)
Phase: Phase 1, Task 1.1 (Quick Wins - Console.log Production Gating)

Files changed:
- NEW: lib/utils/logger.ts (production-safe logging)
- NEW: scripts/replace-console-logs.js (automation tool)
- Modified: 15 lib/*.ts files (console.log → logger.log)
- Modified: .env (DEBUG_LOGS=false)

Next: Task 1.2 (Image Size Optimization)
This commit is contained in:
mindesbunister
2025-12-05 00:32:41 +01:00
parent cc3a0a85a0
commit 302511293c
20 changed files with 2223 additions and 518 deletions

View File

@@ -1,3 +1,5 @@
import { logger } from '../utils/logger'
/**
* Market Data Cache Service
*
@@ -29,7 +31,7 @@ class MarketDataCache {
*/
set(symbol: string, metrics: MarketMetrics): void {
this.cache.set(symbol, metrics)
console.log(
logger.log(
`📊 Cached market data for ${symbol}: ` +
`ADX=${metrics.adx.toFixed(1)} ` +
`ATR=${metrics.atr.toFixed(2)}% ` +
@@ -46,18 +48,18 @@ class MarketDataCache {
const data = this.cache.get(symbol)
if (!data) {
console.log(`⚠️ No cached data for ${symbol}`)
logger.log(`⚠️ No cached data for ${symbol}`)
return null
}
const ageSeconds = Math.round((Date.now() - data.timestamp) / 1000)
if (Date.now() - data.timestamp > this.MAX_AGE_MS) {
console.log(`⏰ Cached data for ${symbol} is stale (${ageSeconds}s old, max 300s)`)
logger.log(`⏰ Cached data for ${symbol} is stale (${ageSeconds}s old, max 300s)`)
return null
}
console.log(`✅ Using fresh TradingView data for ${symbol} (${ageSeconds}s old)`)
logger.log(`✅ Using fresh TradingView data for ${symbol} (${ageSeconds}s old)`)
return data
}
@@ -102,7 +104,7 @@ class MarketDataCache {
*/
clear(): void {
this.cache.clear()
console.log('🗑️ Market data cache cleared')
logger.log('🗑️ Market data cache cleared')
}
}
@@ -112,7 +114,7 @@ let marketDataCache: MarketDataCache | null = null
export function getMarketDataCache(): MarketDataCache {
if (!marketDataCache) {
marketDataCache = new MarketDataCache()
console.log('🔧 Initialized Market Data Cache (5min expiry)')
logger.log('🔧 Initialized Market Data Cache (5min expiry)')
}
return marketDataCache
}