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

Open
geirhoe opened this issue Jul 11, 2024 · 0 comments
Open

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

geirhoe opened this issue Jul 11, 2024 · 0 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant