|
19 | 19 | # Load environment variables |
20 | 20 | load_dotenv() |
21 | 21 |
|
22 | | -# Configure logging |
23 | | -logging.basicConfig(level=logging.INFO) |
| 22 | +# Configure logging with cleaner output |
| 23 | +logging.basicConfig( |
| 24 | + level=logging.INFO, |
| 25 | + format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', |
| 26 | + datefmt='%H:%M:%S' |
| 27 | +) |
24 | 28 | logger = logging.getLogger(__name__) |
25 | 29 |
|
| 30 | +# Reduce Azure and HTTP noise |
| 31 | +logging.getLogger("azure").setLevel(logging.WARNING) |
| 32 | +logging.getLogger("azure.core").setLevel(logging.WARNING) |
| 33 | +logging.getLogger("azure.identity").setLevel(logging.WARNING) |
| 34 | +logging.getLogger("azure.ai").setLevel(logging.WARNING) |
| 35 | +logging.getLogger("urllib3").setLevel(logging.WARNING) |
| 36 | +logging.getLogger("requests").setLevel(logging.WARNING) |
| 37 | +logging.getLogger("httpx").setLevel(logging.WARNING) |
| 38 | +logging.getLogger("httpcore").setLevel(logging.WARNING) |
| 39 | + |
26 | 40 | # Azure AI imports |
27 | 41 | try: |
28 | 42 | from azure.identity import DefaultAzureCredential |
29 | 43 | from azure.ai.agents import AgentsClient |
30 | 44 | from azure.ai.agents.models import McpTool |
31 | 45 | AZURE_AI_AVAILABLE = True |
32 | | - logger.info("✓ Azure AI packages imported successfully") |
| 46 | + logger.info("✅ Azure AI packages available") |
33 | 47 | except ImportError as e: |
34 | 48 | AZURE_AI_AVAILABLE = False |
35 | | - logger.error(f"✗ Azure AI import failed: {e}") |
| 49 | + logger.warning(f"⚠️ Azure AI packages not available: {e}") |
| 50 | + logger.info("ℹ️ App will run in basic mode (todo functionality only)") |
36 | 51 |
|
37 | 52 | # Configuration (all from environment variables from Bicep deployment) |
38 | 53 |
|
@@ -422,6 +437,8 @@ async def create_todo_api(todo_data: dict): |
422 | 437 | created_at=get_current_time() |
423 | 438 | ) |
424 | 439 | todos_storage[next_id] = todo |
| 440 | + logger.info(f"📝 Created todo #{next_id}: '{todo_data['title']}' " |
| 441 | + f"(priority: {todo_data.get('priority', 'medium')})") |
425 | 442 | next_id += 1 |
426 | 443 | return todo.dict() |
427 | 444 | except Exception as e: |
@@ -507,7 +524,9 @@ async def chat_with_ai(chat_message: ChatMessage): |
507 | 524 | detail="Azure AI service is not available. Please configure environment variables for AI chat features." |
508 | 525 | ) |
509 | 526 |
|
| 527 | + logger.info(f"💬 Chat message: '{chat_message.message[:50]}{'...' if len(chat_message.message) > 50 else ''}'") |
510 | 528 | response = await ai_service.chat_with_agent(chat_message.message) |
| 529 | + logger.info(f"🤖 AI response: '{response.response[:50]}{'...' if len(response.response) > 50 else ''}'") |
511 | 530 | return response |
512 | 531 |
|
513 | 532 | @app.get("/api/chat/status") |
@@ -832,4 +851,25 @@ async def mcp_stream_options(): |
832 | 851 |
|
833 | 852 | if __name__ == "__main__": |
834 | 853 | import uvicorn |
835 | | - uvicorn.run(app, host="0.0.0.0", port=8000, log_level="info") |
| 854 | + |
| 855 | + # Print startup message |
| 856 | + print("🚀 Starting To-do MCP Agent Server...") |
| 857 | + print("📝 To-do List: http://localhost:8000") |
| 858 | + print("💬 AI Chat: http://localhost:8000/chat") |
| 859 | + print("🔧 MCP Server: http://localhost:8000/mcp/stream") |
| 860 | + print("❤️ Health Check: http://localhost:8000/health") |
| 861 | + print("-" * 50) |
| 862 | + |
| 863 | + # Configure uvicorn with reduced logging |
| 864 | + log_config = uvicorn.config.LOGGING_CONFIG |
| 865 | + log_config["formatters"]["default"]["fmt"] = "%(asctime)s - %(levelprefix)s %(message)s" |
| 866 | + log_config["formatters"]["access"]["fmt"] = '%(asctime)s - %(levelprefix)s %(client_addr)s - "%(request_line)s" %(status_code)s' |
| 867 | + |
| 868 | + # Reduce access log verbosity |
| 869 | + uvicorn.run( |
| 870 | + app, |
| 871 | + host="0.0.0.0", |
| 872 | + port=8000, |
| 873 | + log_level="warning", # Changed from "info" to "warning" |
| 874 | + access_log=False # Disable detailed access logs |
| 875 | + ) |
0 commit comments