#!/usr/bin/env python3 """ šŸ”‡ Test Log Noise Filtering Quick test to verify werkzeug logs are filtered properly """ import sys import os sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import logging from core import RequestLogFilter def test_log_filter(): """Test the RequestLogFilter to ensure it blocks noise""" print("šŸ” Testing RequestLogFilter...") filter_obj = RequestLogFilter() # Test cases - these should be FILTERED OUT (return False) noisy_logs = [ 'INFO:werkzeug:127.0.0.1 - - [24/Aug/2025 11:17:48] "GET /api/notifications/unread HTTP/1.1" 200 -', 'INFO:werkzeug:127.0.0.1 - - [24/Aug/2025 11:17:48] "GET /api/notifications/unread-count HTTP/1.1" 200 -', 'INFO:werkzeug:127.0.0.1 - - [24/Aug/2025 11:17:58] "GET /api/bots/analysis HTTP/1.1" 200 -', 'INFO:werkzeug:127.0.0.1 - - [24/Aug/2025 11:18:00] "GET /favicon.ico HTTP/1.1" 200 -', 'INFO:werkzeug:127.0.0.1 - - [24/Aug/2025 11:18:00] "GET /api/dashboard/stats HTTP/1.1" 200 -', ] # Test cases - these should be ALLOWED (return True) important_logs = [ 'INFO:werkzeug:127.0.0.1 - - [24/Aug/2025 11:17:48] "POST /api/bots HTTP/1.1" 201 -', 'INFO:werkzeug:127.0.0.1 - - [24/Aug/2025 11:17:48] "PUT /api/bots/1/start HTTP/1.1" 200 -', 'INFO:werkzeug:127.0.0.1 - - [24/Aug/2025 11:17:48] "DELETE /api/bots/1 HTTP/1.1" 200 -', 'INFO:werkzeug:127.0.0.1 - - [24/Aug/2025 11:17:48] "GET /api/bots HTTP/1.1" 404 -', 'INFO:core.bots.trading_bot:Bot 1 [BUY]: Executing trade on EURUSD', 'ERROR:core.mt5.trade:Failed to connect to MT5', 'WARNING:core.strategies:Risk level too high', ] print("\\n🚫 Testing NOISY logs (should be filtered):") for log_msg in noisy_logs: # Create a mock log record record = logging.LogRecord( name='test', level=logging.INFO, pathname='', lineno=0, msg=log_msg, args=(), exc_info=None ) should_show = filter_obj.filter(record) status = "āŒ FILTERED" if not should_show else "āš ļø SHOWING" print(f" {status}: {log_msg[:80]}...") if should_show: print(f" āš ļø WARNING: This noisy log is still showing!") print("\\nāœ… Testing IMPORTANT logs (should be shown):") for log_msg in important_logs: record = logging.LogRecord( name='test', level=logging.INFO, pathname='', lineno=0, msg=log_msg, args=(), exc_info=None ) should_show = filter_obj.filter(record) status = "āœ… SHOWING" if should_show else "āŒ FILTERED" print(f" {status}: {log_msg[:80]}...") if not should_show: print(f" āš ļø WARNING: This important log is being filtered!") print("\\nšŸŽÆ SUMMARY:") print("Your terminal will now only show:") print(" āœ… Trading bot activities") print(" āœ… POST/PUT/DELETE requests (important actions)") print(" āœ… Error messages (4xx, 5xx)") print(" āœ… Warnings and critical messages") print("\\n🚫 Filtered out (noise):") print(" āŒ GET requests with 200 status") print(" āŒ Notification polling") print(" āŒ Dashboard data polling") print(" āŒ Static files and favicon") print("\\nšŸŽ‰ Your backtesting terminal will be MUCH quieter now!") if __name__ == "__main__": test_log_filter()