You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used the GitHub search to find a similar question and didn't find it.
I searched in the documentation/README.
I already searched in Google "How to do X" and didn't find any information.
I already read and followed all the tutorial in the docs/README and didn't find an answer.
Commit to Help
I commit to help with one of those options 👆
Example Code
import logging
import sys
from functools import wraps
from typing import Callable, Dict, Optional
from fastapi import BackgroundTasks, Depends, HTTPException, Request, Response, status
from sqlmodel import Session
from starlette.responses import JSONResponse
from app.api.deps.deps import CurrentUser, SessionDep
from app.core.tier_config import ENDPOINT_TO_FEATURE_MAP, EXEMPT_PATHS
from app.models import User
from app.services.quota_service import QuotaService
# Configure logging
logger = logging.getLogger(__name__)
async def rate_limit_dependency(
request: Request,
response: Response,
background_tasks: BackgroundTasks,
session: SessionDep,
current_user: CurrentUser,
) -> None:
"""
FastAPI dependency for rate limiting based on user tier and quota
"""
# These logs don't appear anywhere
logger.debug("testing logging")
logger.info("testing logging")
logger.warn("testing logging")
logger.warning("testing logging")
logging.debug("testing logging")
logging.info("testing logging")
logging.warn("testing logging")
logging.warning("testing logging")
# This doesn't appear either!
print("===== RATE LIMITING RUNNING =====", file=sys.stderr)
# The rest of the function works fine - we get 429 errors when expected
if current_user.is_superuser:
return
# Code continues...
Description
I'm having a widespread issue with logging in our FastAPI application. Logs from certain parts of the application appear in the console output, while logs from other parts don't show up at all. Even direct print() statements to sys.stderr are not visible from some modules.
For example:
Logs from app/main.py and app/membership_init.py are visible
Logs from API routes, dependencies, and services generally don't appear
What makes this particularly confusing is that I see logs from some modules but not others, despite using the same logging configuration. For instance, this log appears:
2025-03-23 13:27:12,237 - app.main - INFO - Initializing application
But logs from other parts of the application, particularly in the API routes and dependencies, are completely invisible. This happens with logs at all levels (debug, info, warning) and even with direct print statements.
The affected code definitely runs because the functionality works correctly (e.g., rate limits are enforced, routes return expected responses), but no logs appear.
Operating System
macOS, Other
Operating System Details
Running locally in Docker containers with the FastAPI template setup. This is a development environment, not production.
docker compose watch
docker compose logs -f backend
Python Version
3.10
Additional Context
The application is structured using the full-stack-fastapi-template
Environment is set to "local" in .env file (ENVIRONMENT=local)
I've confirmed the code is definitely running because functionality works as expected
I've tried:
Setting log level to DEBUG in app/main.py
Using direct print statements to stderr
Using fully qualified logger names instead of name
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
First Check
Commit to Help
Example Code
Description
I'm having a widespread issue with logging in our FastAPI application. Logs from certain parts of the application appear in the console output, while logs from other parts don't show up at all. Even direct
print()
statements tosys.stderr
are not visible from some modules.For example:
Logs from
app/main.py
andapp/membership_init.py
are visibleLogs from API routes, dependencies, and services generally don't appear
What makes this particularly confusing is that I see logs from some modules but not others, despite using the same logging configuration. For instance, this log appears:
But logs from other parts of the application, particularly in the API routes and dependencies, are completely invisible. This happens with logs at all levels (debug, info, warning) and even with direct print statements.
The affected code definitely runs because the functionality works correctly (e.g., rate limits are enforced, routes return expected responses), but no logs appear.
Operating System
macOS, Other
Operating System Details
Running locally in Docker containers with the FastAPI template setup. This is a development environment, not production.
docker compose watch
docker compose logs -f backend
Python Version
3.10
Additional Context
Beta Was this translation helpful? Give feedback.
All reactions