Skip to content

disable_stack_trace suppresses exception logging entirely instead of only stack traces #4510

@bookin

Description

@bookin

Description

When using StructLoggingConfig.disable_stack_trace with the Structlog plugin, exceptions matching the configured HTTP status codes / exception classes are not logged at all — neither message nor stack trace.

From the docs I expected that only the stack trace would be suppressed, while a one‑line error log (e.g. with message, level, path) would still be emitted.

The relevant code path seems to be in ExceptionHandlerMiddleware.handle_exception_logging

If disable_stack_trace contains 404 or NotFoundException,
exc_detail.isdisjoint(disable_stack_trace) is False,
so exception_logging_handler is never called.

This effectively disables logging for these exceptions, not just their stack traces.

Is the current behavior (no log at all when status/exception is listed in disable_stack_trace) intentional, or is this a bug?

URL to code causing the issue

No response

MCVE

from litestar import Litestar, get
from litestar.exceptions import NotFoundException
from litestar.logging import StructLoggingConfig
from litestar.logging.config import LoggingConfig, default_logger_factory
from litestar.middleware.logging import LoggingMiddlewareConfig
from litestar.plugins.structlog import StructlogConfig, StructlogPlugin


@get("/404")
async def trigger_404() -> None:
    raise NotFoundException()


structlog_config = StructlogConfig(
    structlog_logging_config=StructLoggingConfig(
        log_exceptions="always",
        disable_stack_trace={404, NotFoundException},
        standard_lib_logging_config=LoggingConfig(
            # root/stdlib config here, e.g.
            root={"level": "INFO", "handlers": ["queue_listener"]},
        ),
        logger_factory=default_logger_factory(as_json=False),
    ),
    middleware_logging_config=LoggingMiddlewareConfig(),
)

app = Litestar(
    route_handlers=[trigger_404],
    plugins=[StructlogPlugin(config=structlog_config)],
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug 🐛This is something that is not working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions