Skip to content

Commit 8ffa798

Browse files
committed
simplify logging
1 parent a0980e4 commit 8ffa798

1 file changed

Lines changed: 45 additions & 5 deletions

File tree

main.py

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,35 @@
1919
# Load environment variables
2020
load_dotenv()
2121

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+
)
2428
logger = logging.getLogger(__name__)
2529

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+
2640
# Azure AI imports
2741
try:
2842
from azure.identity import DefaultAzureCredential
2943
from azure.ai.agents import AgentsClient
3044
from azure.ai.agents.models import McpTool
3145
AZURE_AI_AVAILABLE = True
32-
logger.info(" Azure AI packages imported successfully")
46+
logger.info(" Azure AI packages available")
3347
except ImportError as e:
3448
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)")
3651

3752
# Configuration (all from environment variables from Bicep deployment)
3853

@@ -422,6 +437,8 @@ async def create_todo_api(todo_data: dict):
422437
created_at=get_current_time()
423438
)
424439
todos_storage[next_id] = todo
440+
logger.info(f"📝 Created todo #{next_id}: '{todo_data['title']}' "
441+
f"(priority: {todo_data.get('priority', 'medium')})")
425442
next_id += 1
426443
return todo.dict()
427444
except Exception as e:
@@ -507,7 +524,9 @@ async def chat_with_ai(chat_message: ChatMessage):
507524
detail="Azure AI service is not available. Please configure environment variables for AI chat features."
508525
)
509526

527+
logger.info(f"💬 Chat message: '{chat_message.message[:50]}{'...' if len(chat_message.message) > 50 else ''}'")
510528
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 ''}'")
511530
return response
512531

513532
@app.get("/api/chat/status")
@@ -832,4 +851,25 @@ async def mcp_stream_options():
832851

833852
if __name__ == "__main__":
834853
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

Comments
 (0)