Skip to content

Commit

Permalink
Fix key order in contextvar docs once and for all
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Feb 18, 2021
1 parent 765d7f0 commit 71727c9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions docs/contextvars.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,15 @@ The general flow is:
>>> configure(
... processors=[
... merge_contextvars,
... structlog.processors.KeyValueRenderer(),
... structlog.processors.KeyValueRenderer(key_order=["event", "a"]),
... ]
... )
>>> log = structlog.get_logger()
>>> # At the top of your request handler (or, ideally, some general
>>> # middleware), clear the threadlocal context and bind some common
>>> # values:
>>> clear_contextvars()
>>> bind_contextvars(a=1)
>>> bind_contextvars(b=2)
>>> bind_contextvars(a=1, b=2)
>>> # Then use loggers as per normal
>>> # (perhaps by using structlog.get_logger() to create them).
>>> log.msg("hello")
Expand All @@ -57,6 +56,8 @@ The general flow is:
>>> log.msg("world")
event='world' a=1
>>> # And when we clear the threadlocal state again, it goes away.
>>> # a=None is printed due to the key_order argument passed to
>>> # KeyValueRenderer, but it is NOT present anymore.
>>> clear_contextvars()
>>> log.msg("hi there")
event='hi there'
event='hi there' a=None

0 comments on commit 71727c9

Please sign in to comment.