This document describes the comprehensive logging system implemented for FastRTC services, including detailed request/response tracking for both the gRPC OCR service and CaloreportService.
Overview
The logging implementation provides:
- Request tracking with unique IDs for correlation
 - Detailed error logging with context and retry information
 - Performance metrics for request/response timing
 - Configurable log levels and output formats
 - Service-specific loggers for fine-grained control
 
Services Covered
  
  
  1. gRPC OCR Service Client (src/ocr/grpc_client.py)
- Connection establishment and health checks
 - Request encoding and transmission
 - Response parsing and validation
 - Retry logic and error handling
 - Performance timing
 
  
  
  2. CaloreportService Client (src/report_svc/client.py)
- HTTP request/response cycles
 - JSON parsing and validation
 - Connection errors and timeouts
 - Retry attempts and backoff
 - Response data analysis
 
Log Message Format
Request Tracking
All requests are assigned a unique 8-character ID for correlation:
[a1b2c3d4] π Starting OCR request to localhost:50051
[a1b2c3d4] π€ Attempt 1/3 - Encoding image data
[a1b2c3d4] β
 OCR completed in 0.234s: engine=easyocr, confidence=0.87
Log Levels Used
INFO Level
- Service initialization
 - Request start/completion
 - Successful operations
 - Retry attempts
 
DEBUG Level
- Request parameters and configuration
 - Encoding/decoding steps
 - Response parsing details
 - Performance metrics
 
ERROR Level
- Connection failures
 - Request timeouts
 - Parsing errors
 - Retry exhaustion
 
WARNING Level
- Service degradation
 - Retry-able errors
 - Configuration issues
 
Example Log Output
gRPC OCR Service
2025-08-28 02:38:56 | src.ocr.grpc_client | INFO | extract_text_from_region:123 | [d6b4c25b] π Starting OCR request to localhost:50051
2025-08-28 02:38:56 | src.ocr.grpc_client | DEBUG | extract_text_from_region:124 | [d6b4c25b] Request params: bbox=[0, 0, 50, 50], class_name=None, engine=easyocr, languages=['en'], gpu=True
2025-08-28 02:38:56 | src.ocr.grpc_client | DEBUG | extract_text_from_region:131 | [d6b4c25b] π€ Attempt 1/3 - Encoding image data
2025-08-28 02:38:56 | src.ocr.grpc_client | DEBUG | extract_text_from_region:137 | [d6b4c25b] β
 Image encoded successfully: 2048 bytes
2025-08-28 02:38:56 | src.ocr.grpc_client | DEBUG | extract_text_from_region:148 | [d6b4c25b] π‘ Sending gRPC request (timeout=30s)
2025-08-28 02:38:56 | src.ocr.grpc_client | ERROR | extract_text_from_region:170 | [d6b4c25b] π΄ gRPC error on attempt 1/3: code=UNAVAILABLE, details=failed to connect
CaloreportService
2025-08-28 02:38:56 | src.report_svc.client | INFO | get_delivery_skus:89 | [24f8f831] π¦ Starting CaloreportService request for delivery_id: test-delivery-id
2025-08-28 02:38:56 | src.report_svc.client | DEBUG | get_delivery_skus:103 | [24f8f831] π Request details: URL=http://localhost:5270/api/Delivery/test-delivery-id/skus, timeout=30s, max_retries=2
2025-08-28 02:38:56 | src.report_svc.client | DEBUG | get_delivery_skus:111 | [24f8f831] π‘ Attempt 1/3 - Sending HTTP GET request
2025-08-28 02:38:56 | src.report_svc.client | DEBUG | get_delivery_skus:119 | [24f8f831] π₯ Response received in 0.145s: status=200
2025-08-28 02:38:56 | src.report_svc.client | INFO | get_delivery_skus:137 | [24f8f831] β
 CaloreportService request successful in 0.145s: invoice=INV-001, skus=5, delivery_id=test-delivery-id
Configuration
Environment Variables
Configure logging behavior using environment variables:
# Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
export FASTRTC_LOG_LEVEL=DEBUG
# Optional log file path
export FASTRTC_LOG_FILE=/var/log/fastrtc/app.log
# Enable/disable console logging (true/false)
export FASTRTC_LOG_CONSOLE=true
# Log format style (detailed/simple)
export FASTRTC_LOG_FORMAT=detailed
Programmatic Configuration
from src.utils.logger import setup_fastrtc_logging
# Setup with custom configuration
setup_fastrtc_logging(
    level="DEBUG",
    log_file="/tmp/fastrtc.log",
    enable_console=True,
    format_style="detailed"
)
# Or use environment variables
from src.utils.logger import setup_logging_from_env
setup_logging_from_env()
Logger Hierarchy
The logging system uses a hierarchical structure:
root
βββ src.ocr.grpc_client          (DEBUG level)
βββ src.report_svc.client        (DEBUG level)
βββ src.core.detector            (INFO level)
βββ src.ui                       (INFO level)
Emoji Guide
The logging uses emoji for quick visual identification:
| Emoji | Meaning | 
|---|---|
| π | Request started | 
| π€ | Data encoding/preparation | 
| π‘ | Network transmission | 
| π₯ | Response received | 
| β | Successful operation | 
| π | Retry attempt | 
| π΄ | Error occurred | 
| β | Critical failure | 
| β οΈ | Warning condition | 
| π¦ | Service request | 
| π | Network operation | 
| π | Configuration/metadata | 
| π | Statistics/metrics | 
| π« | Resource not found | 
| π | Location/tracking info | 
Performance Monitoring
Logs include timing information for performance analysis:
- Request duration: Time from start to completion
 - Network latency: Time spent in network communication
 - Processing time: Time spent in data processing
 - Retry delays: Time spent waiting between retries
 
Error Analysis
Common Error Patterns
- Connection Refused - Service not running
 - Timeout - Service overloaded or network issues
 - 404 Not Found - Resource doesn't exist
 - JSON Parse Error - Invalid response format
 - gRPC UNAVAILABLE - OCR service down
 
Debugging Tips
- Search for request ID to trace entire request lifecycle
 - Check INFO level for high-level operation status
 - Use DEBUG level for detailed parameter analysis
 - Monitor retry patterns for service health
 - Analyze timing data for performance optimization
 
Integration with FastRTC
The logging system is automatically initialized when using the FastRTC application. To enable detailed logging:
# Enable debug logging
export FASTRTC_LOG_LEVEL=DEBUG
# Run application
make run ENV=dev
Log Rotation and Management
For production deployment:
- Configure log file rotation using 
logrotate - Monitor disk space usage
 - Set up log aggregation if running multiple instances
 - Consider structured logging formats for automated analysis
 
Best Practices
- Use appropriate log levels - DEBUG for development, INFO for production
 - Include context - Request IDs help correlate related log entries
 - Log performance metrics - Help identify bottlenecks
 - Sanitize sensitive data - Don't log API keys or personal information
 - Monitor log volume - High DEBUG logging can impact performance
 
Troubleshooting
High Log Volume
- Reduce log level from DEBUG to INFO
 - Filter specific loggers if needed
 - Use log sampling for high-frequency operations
 
Missing Logs
- Check logger configuration
 - Verify log level settings
 - Ensure handlers are properly configured
 
Performance Impact
- Monitor logging overhead in production
 - Consider asynchronous logging for high-throughput scenarios
 - Balance between detail and performance
 
    
Top comments (0)