Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

watchtower dies with I'm trying to filter uvicorn access logs #204

Closed
geirhoe opened this issue Jul 11, 2024 · 2 comments
Closed

watchtower dies with I'm trying to filter uvicorn access logs #204

geirhoe opened this issue Jul 11, 2024 · 2 comments

Comments

@geirhoe
Copy link

geirhoe commented Jul 11, 2024

running the code below, produces a warning from watchtower

WatchtowerWarning: Received message after logging system shutdown
warnings.warn("Received message after logging system shutdown", WatchtowerWarning)

and no logs are forwarded to cloudwatch. after the first access to the / path.

using curl: curl -vs http://localhost:8080/ 2>&1

from fastapi import FastAPI, Response
from fastapi.responses import HTMLResponse
import uvicorn
import logging
import watchtower

app = FastAPI()

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("logger_name")
#    logger.propagate = False
logger.setLevel(logging.INFO)
logger.addHandler(watchtower.CloudWatchLogHandler(
    log_group_name="log_group_name"
))


class EndpointFilter(logging.Filter):
    def filter(self, record: logging.LogRecord) -> bool:
        return record.getMessage().find("/health") == -1


logging.getLogger("uvicorn.access").addFilter(EndpointFilter())


@app.get("/", status_code=200)
async def hello():
    logger.info("hello called")
    return Response(content="world", media_type="text")

if __name__ == "__main__":
    port = 8080
    logger.info(f"Booting up, listening port is set to {port}")
    uvicorn.run(app, host="0.0.0.0", port=port, server_header=False, date_header=False)
    logger.info("Server done")

Please advice.

@kislyuk
Copy link
Owner

kislyuk commented Dec 31, 2024

What have you tried to solve the problem? Does the same issue occur without the filter?

@geirih

This comment was marked as off-topic.

@kislyuk kislyuk closed this as completed Jan 3, 2025
Repository owner locked as off-topic and limited conversation to collaborators Jan 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants