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

LoggerMiddleware not outputting anything #276

Closed
drnextgis opened this issue Mar 24, 2021 · 4 comments
Closed

LoggerMiddleware not outputting anything #276

drnextgis opened this issue Mar 24, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@drnextgis
Copy link
Contributor

When I run titiler with debug enabled:

$ TITILER_API_DEBUG=1 uvicorn titiler.main:app --reload

I expect to see something printed in stdout but there is nothing.

@drnextgis drnextgis added the bug Something isn't working label Mar 24, 2021
@vincentsarago
Copy link
Member

can you try with --log-level debug ?

@drnextgis
Copy link
Contributor Author

same thing:

$ TITILER_API_DEBUG=1 uvicorn titiler.main:app --reload --log-level debug
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [24825] using watchgod
INFO:     Started server process [24827]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     127.0.0.1:44610 - "GET /cog/info?url=https%3A%2F%2Fgithub.com%2Fmapbox%2Frasterio%2Fblob%2Fmaster%2Ftests%2Fdata%2FRGB2.byte.tif%3Fraw%3Dtrue HTTP/1.1" 200 OK
INFO:     127.0.0.1:44984 - "GET /healthz HTTP/1.1" 200 OK

@drnextgis
Copy link
Contributor Author

@vincentsarago what do you think about this fix?

diff --git a/titiler/middleware.py b/titiler/middleware.py
index d3c5841..9b90c41 100644
--- a/titiler/middleware.py
+++ b/titiler/middleware.py
@@ -58,6 +58,7 @@ class LoggerMiddleware(BaseHTTPMiddleware):
         super().__init__(app)
         self.logger = logger
         logger.setLevel(logging.DEBUG)
+        logger.addHandler(logging.StreamHandler())
 
         self.querystrings = querystrings
         self.headers = headers

@vincentsarago
Copy link
Member

vincentsarago commented Mar 24, 2021

@drnextgis I think this is a Uvicorn bug.
ref: fastapi/fastapi#2019

The current implementation works fine when not using uvicorn (e.g. in AWS Lambda)

I've been able to print the logs by using a config file

version: 1
  
disable_existing_loggers: False

formatters:
  console:
    format: "%(levelname)s\t%(name)s\t%(message)s"

handlers:
  console:
    class: logging.StreamHandler
    formatter: console
    stream: ext://sys.stderr
    level: 0

root:
  handlers: [ console ]
  level: 0

TITILER_API_DEBUG=TRUE uvicorn titiler.main:app --reload --log-config log-config.yaml

ref: encode/uvicorn#944

I'm going to close this issue because I believe this is not related to TiTiler itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants