Skip to content

Commit

Permalink
docs/glossary: add context
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Dec 29, 2023
1 parent 444e6d3 commit 0ea03fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ log = structlog.get_logger()
- For brevity and to enable doctests, all further examples in *structlog*'s documentation use the more simplistic {class}`~structlog.processors.KeyValueRenderer()` without timestamps.
:::

Here you go, structured logging!
There you go, structured logging!


However, this alone wouldn't warrant its own package.
Expand Down Expand Up @@ -107,7 +107,7 @@ At this point, you'll be tempted to write a closure like:

```python
def log_closure(event):
log.info(event, user_agent=user_agent, peer_ip=peer_ip)
log.info(event, user_agent=user_agent, peer_ip=peer_ip)
```

inside of the view.
Expand Down
12 changes: 11 additions & 1 deletion docs/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,25 @@ Event Dictionary
Bound Logger
An instance of a {class}`structlog.typing.BindableLogger` that is returned by either {func}`structlog.get_logger` or the bind/unbind/new methods on it.

As the name suggests, it's possible to bind key-value pairs to it -- this data is called the **context** of the logger.
As the name suggests, it's possible to bind key-value pairs to it -- this data is called the {term}`context` of the logger.

Its methods are the user's logging API and depend on the type of the bound logger.
The two most common implementations are {class}`structlog.BoundLogger` and {class}`structlog.stdlib.BoundLogger`.

Bound loggers are **immutable**.
The context can only be modified by creating a new bound logger using its `bind()`and `unbind()` methods.

:::{seealso}
{doc}`bound-loggers`
:::

Context
A dictionary of key-value pairs belonging to a {term}`bound logger`.
When a log entry is logged out, the context is the base for the event dictionary with the keyword arguments of the logging method call merged in.

Bound loggers are **immutable**, so it's not possible to modify a context directly.
But you can create a new bound logger with a different context using its `bind()` and `unbind()` methods.

Native Loggers
Loggers created using {func}`structlog.make_filtering_bound_logger` which includes the default configuration.

Expand Down

0 comments on commit 0ea03fb

Please sign in to comment.