The expectation is that any logging done is derivative of the root logger if not otherwise specified.
Perhaps I've done this wrong - but I don't want to see debug level logs when I have set the level to INFO
/20
or above.
No response
import logging
import structlog
from litestar import Litestar, get
from litestar.plugins.structlog import StructlogPlugin
from litestar.logging import LoggingConfig, StructLoggingConfig
from litestar.middleware.logging import LoggingMiddlewareConfig
from litestar.plugins.structlog import StructlogConfig
logging_config = StructlogConfig(
structlog_logging_config=StructLoggingConfig(
log_exceptions="always",
traceback_line_limit=4,
standard_lib_logging_config=LoggingConfig(
root={"level": logging.getLevelName(20), "handlers": ["queue_listener"]},
loggers={
"uvicorn.access": {
"propagate": False,
"level": 30,
"handlers": ["queue_listener"],
},
"uvicorn.error": {
"propagate": False,
"level": 20,
"handlers": ["queue_listener"],
},
},
),
),
middleware_logging_config=LoggingMiddlewareConfig(
request_log_fields=["method", "path", "path_params", "query"],
response_log_fields=["status_code"],
),
)
logger = structlog.get_logger()
@get("/")
async def foo() -> None:
logger.debug("you shouldnt see this")
pass
structlog = StructlogPlugin(config=logging_config)
app = Litestar(route_handlers=[foo], plugins=[structlog])
1. Create and run app: `litestar --app asgi:app run`
2. `curl 0.0.0.0:8000`
3. See error
2024-04-23T22:43:18.589449Z [debug ] you shouldnt see this
INFO: 127.0.0.1:58488 - "GET / HTTP/1.1" 200 OK
No response
β litestar --app asgi:app run
Using Litestar app from env: 'asgi:app'
Starting server process ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββ
β Litestar version β 2.8.2 β
β Debug mode β Disabled β
β Python Debugger on exception β Disabled β
β CORS β Disabled β
β CSRF β Disabled β
β OpenAPI β Enabled path=/schema β
β Compression β Disabled β
β Middlewares β LoggingMiddleware β
ββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββ
2024-04-23T22:43:18.589367Z [info ] HTTP Request method=GET path=/ path_params={} query={}
2024-04-23T22:43:18.589449Z [debug ] you shouldnt see this
INFO: 127.0.0.1:58488 - "GET / HTTP/1.1" 200 OK
2024-04-23T22:43:18.589767Z [info ] HTTP Response status_code=200
main
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too