This commit is contained in:
Dobromir Popov
2025-07-23 13:39:41 +03:00
parent 944a7b79e6
commit df17a99247
13 changed files with 663 additions and 695 deletions

69
test_safe_logging.py Normal file
View File

@ -0,0 +1,69 @@
#!/usr/bin/env python3
"""
Test script to verify safe_logging functionality
This script tests that the safe logging module properly handles:
1. Non-ASCII characters (emojis, smart quotes)
2. UTF-8 encoding
3. Error handling on Windows
"""
import logging
from safe_logging import setup_safe_logging
def test_safe_logging():
"""Test the safe logging module with various character types"""
# Setup safe logging
setup_safe_logging()
logger = logging.getLogger(__name__)
print("Testing Safe Logging Module...")
print("=" * 50)
# Test regular ASCII messages
logger.info("Regular ASCII message - this should work fine")
# Test messages with emojis
logger.info("Testing emojis: 🚀 💰 📈 📊 🔥")
# Test messages with smart quotes and special characters
logger.info("Testing smart quotes: Hello World Test")
# Test messages with various Unicode characters
logger.info("Testing Unicode: café résumé naïve Ω α β γ δ")
# Test messages with mixed content
logger.info("Mixed content: Regular text with emojis 🎉 and quotes like this")
# Test error messages with special characters
logger.error("Error with special chars: ❌ Failed to process €100.50")
# Test warning messages
logger.warning("Warning with symbols: ⚠️ Temperature is 37°C")
# Test debug messages
logger.debug("Debug info: Processing file data.txt at 95% completion ✓")
# Test exception handling with special characters
try:
raise ValueError("Error with emoji: 💥 Something went wrong!")
except Exception as e:
logger.exception("Exception caught with special chars: %s", str(e))
# Test formatting with special characters
symbol = "ETH/USDT"
price = 2500.50
change = 2.3
logger.info(f"Price update for {symbol}: ${price:.2f} (+{change}% 📈)")
# Test large message with many special characters
large_msg = "Large message: " + "🔄" * 50 + " Processing complete ✅"
logger.info(large_msg)
print("=" * 50)
print("✅ Safe logging test completed!")
print("If you see this message, all logging calls were successful.")
print("Check the log file at logs/safe_logging.log for the complete output.")
if __name__ == "__main__":
test_safe_logging()