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'
/**
* Telegram notification utilities
*
@@ -36,7 +38,7 @@ export async function sendPositionClosedNotification(options: TelegramNotificati
const chatId = process.env.TELEGRAM_CHAT_ID
if (!token || !chatId) {
console.log('⚠️ Telegram credentials not configured, skipping notification')
logger.log('⚠️ Telegram credentials not configured, skipping notification')
return
}
@@ -77,7 +79,7 @@ ${options.maxDrawdown ? `\n📉 Max Drawdown: -${options.maxDrawdown.toFixed(2)}
const errorData = await response.json()
console.error('❌ Telegram notification failed:', errorData)
} else {
console.log('✅ Telegram notification sent')
logger.log('✅ Telegram notification sent')
}
} catch (error) {
console.error('❌ Error sending Telegram notification:', error)
@@ -243,7 +245,7 @@ async function sendWithdrawalNotification(options: TelegramWithdrawalOptions): P
const chatId = process.env.TELEGRAM_CHAT_ID
if (!token || !chatId) {
console.log('⚠️ Telegram credentials not configured, skipping notification')
logger.log('⚠️ Telegram credentials not configured, skipping notification')
return
}
@@ -273,7 +275,7 @@ async function sendWithdrawalNotification(options: TelegramWithdrawalOptions): P
const errorData = await response.json()
console.error('❌ Telegram notification failed:', errorData)
} else {
console.log('✅ Telegram withdrawal notification sent')
logger.log('✅ Telegram withdrawal notification sent')
}
} catch (error) {
console.error('❌ Error sending Telegram notification:', error)
@@ -290,7 +292,7 @@ export async function sendTelegramMessage(message: string): Promise<void> {
const chatId = process.env.TELEGRAM_CHAT_ID
if (!token || !chatId) {
console.log('⚠️ Telegram credentials not configured, skipping notification')
logger.log('⚠️ Telegram credentials not configured, skipping notification')
return
}