Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified docs/_static/console_renderer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/contextvars.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This context is safe to be used both in threaded as well as asynchronous code.
:::{warning}
Since the storage mechanics of your context variables is different for each concurrency method, they are _isolated_ from each other.

This can be a problem in hybrid applications like those based on [Starlette](https://www.starlette.io) (this [includes FastAPI](https://github.com/tiangolo/fastapi/discussions/5999)) where context variables set in a synchronous context don't appear in logs from an async context and vice versa.
This can be a problem in hybrid applications like those based on [Starlette](https://www.starlette.io) (this [includes FastAPI](https://github.com/fastapi/fastapi/discussions/5999)) where context variables set in a synchronous context don't appear in logs from an async context and vice versa.
:::

The general flow is:
Expand Down
2 changes: 1 addition & 1 deletion docs/thread-local.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ These functions map 1:1 to the {doc}`contextvars` APIs, so please use those inst

## Thread-local contexts

*structlog* also provides thread-local context storage in a form that you may already know from [*Flask*](https://flask.palletsprojects.com/en/latest/design/#thread-locals) and that makes the *entire context* global to your thread or greenlet.
*structlog* also provides thread-local context storage in a form that you may already know from Flask and that makes the *entire context* global to your thread or greenlet.

This makes its behavior more difficult to reason about which is why we generally recommend to use the {func}`~structlog.contextvars.merge_contextvars` route.
Therefore, there are currently no plans to re-implement this behavior on top of context variables.
Expand Down
7 changes: 5 additions & 2 deletions show_off.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ class SomeClass:
log.warning("uh-uh!")
log.error("omg", a_dict={"a": 42, "b": "foo"})
log.critical("wtf", what=SomeClass(x=1, y="z"))
structlog.dev.ConsoleRenderer.get_active().colors = False

# Demonstrate writable properties
cr = structlog.dev.ConsoleRenderer.get_active()
cr.colors = False
log.info("where are the colors!?", colors="gone")
structlog.dev.ConsoleRenderer.get_active().colors = True
cr.colors = True
log.info("there they are!", colors="back")


Expand Down
Loading