fix(log): Enable the logging level when enabling the DEBUG environment variable (#793)

This commit is contained in:
Willem Jiang
2026-01-01 09:32:42 +08:00
committed by GitHub
parent a71b6bc41f
commit 275aab9d42
3 changed files with 25 additions and 3 deletions

View File

@@ -79,12 +79,18 @@ if __name__ == "__main__":
if args.reload:
reload = True
# Check for DEBUG environment variable to override log level
if os.getenv("DEBUG", "").lower() in ("true", "1", "yes"):
log_level = "debug"
else:
log_level = args.log_level
try:
logger.info(f"Starting DeerFlow API server on {args.host}:{args.port}")
logger.info(f"Log level: {args.log_level.upper()}")
logger.info(f"Log level: {log_level.upper()}")
# Set the appropriate logging level for the src package if debug is enabled
if args.log_level.lower() == "debug":
if log_level.lower() == "debug":
logging.getLogger("src").setLevel(logging.DEBUG)
logging.getLogger("langchain").setLevel(logging.DEBUG)
logging.getLogger("langgraph").setLevel(logging.DEBUG)
@@ -95,7 +101,7 @@ if __name__ == "__main__":
host=args.host,
port=args.port,
reload=reload,
log_level=args.log_level,
log_level=log_level,
)
except Exception as e:
logger.error(f"Failed to start server: {str(e)}")

View File

@@ -9,6 +9,19 @@ import os
from typing import Annotated, Any, List, Optional, cast
from uuid import uuid4
# Load environment variables from .env file FIRST
# This must happen before checking DEBUG environment variable
from dotenv import load_dotenv
load_dotenv()
# Configure logging based on DEBUG environment variable
# This must happen early, before other modules are imported
_debug_mode = os.getenv("DEBUG", "").lower() in ("true", "1", "yes")
if _debug_mode:
logging.getLogger("src").setLevel(logging.DEBUG)
logging.getLogger("langchain").setLevel(logging.DEBUG)
logging.getLogger("langgraph").setLevel(logging.DEBUG)
from fastapi import FastAPI, HTTPException, Query, UploadFile
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import Response, StreamingResponse

View File

@@ -16,7 +16,10 @@ logging.basicConfig(
def enable_debug_logging():
"""Enable debug level logging for more detailed execution information."""
# Must also set root logger level to allow DEBUG messages to propagate
logging.getLogger("src").setLevel(logging.DEBUG)
logging.getLogger("langchain").setLevel(logging.DEBUG)
logging.getLogger("langgraph").setLevel(logging.DEBUG)
logger = logging.getLogger(__name__)