Skip to content

feat(log): disable stack trace#4086

Merged
cofin merged 9 commits intolitestar-org:mainfrom
Harshal6927:feat/disable-stack-trace
Apr 6, 2025
Merged

feat(log): disable stack trace#4086
cofin merged 9 commits intolitestar-org:mainfrom
Harshal6927:feat/disable-stack-trace

Conversation

@Harshal6927
Copy link
Copy Markdown
Member

@Harshal6927 Harshal6927 commented Apr 5, 2025

Description

In the logger configuration, users can specify a set of status codes and exception types for which Litestar will not log the full stack trace.

Closes

#4081

Example

import uvicorn

from litestar import Litestar, get
from litestar.logging import LoggingConfig


@get("/")
async def index() -> str:
    return "Hello, world!"


@get("/value-error")
async def value_error() -> None:
    raise ValueError("This is a test value error.")  # not log the stack trace


@get("/name-error")
async def name_error() -> None:
    raise NameError("This is a test name error.")


app = Litestar(
    route_handlers=[index, value_error, name_error],
    debug=True,
    logging_config=LoggingConfig(
        disable_stack_trace={404, ValueError}  # disable_stack_trace: set[Union[int, type[Exception]]]
    ),
)


if __name__ == "__main__":
    uvicorn.run(app=app, port=8621)

@Harshal6927 Harshal6927 requested review from a team as code owners April 5, 2025 23:00
@Harshal6927 Harshal6927 changed the title Feat/disable stack trace feat(log): disable stack trace Apr 5, 2025
@github-actions github-actions bot added area/docs This PR involves changes to the documentation type/feat labels Apr 5, 2025
@cofin
Copy link
Copy Markdown
Member

cofin commented Apr 6, 2025

Changes look good to me. Let's add some tests and we can get this merged.

@cofin cofin force-pushed the feat/disable-stack-trace branch from bb47875 to f032087 Compare April 6, 2025 14:31
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.34%. Comparing base (c0a54d5) to head (4a945cc).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4086   +/-   ##
=======================================
  Coverage   98.34%   98.34%           
=======================================
  Files         348      348           
  Lines       15833    15841    +8     
  Branches     1749     1749           
=======================================
+ Hits        15571    15579    +8     
  Misses        125      125           
  Partials      137      137           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2025

Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/4086

Copy link
Copy Markdown
Member

@cofin cofin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cofin cofin merged commit 87766be into litestar-org:main Apr 6, 2025
88 of 95 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants