Skip to content

Commit

Permalink
blacken stdlib example from docs (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
wimglenn authored Sep 13, 2023
1 parent 039d6d3 commit bb10cbb
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions docs/standard-library.md
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,10 @@ formatter = structlog.stdlib.ProcessorFormatter(
foreign_pre_chain=shared_processors,
# These run on ALL entries after the pre_chain is done.
processors=[
# Remove _record & _from_structlog.
structlog.stdlib.ProcessorFormatter.remove_processors_meta,
structlog.dev.ConsoleRenderer(),
],
# Remove _record & _from_structlog.
structlog.stdlib.ProcessorFormatter.remove_processors_meta,
structlog.dev.ConsoleRenderer(),
],
)
```

Expand Down Expand Up @@ -456,34 +456,36 @@ pre_chain = [
timestamper,
]


def extract_from_record(_, __, event_dict):
"""
Extract thread and process names and add them to the event dict.
"""
record = event_dict["_record"]
event_dict["thread_name"] = record.threadName
event_dict["process_name"] = record.processName

return event_dict

logging.config.dictConfig({

logging.config.dictConfig(
{
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"plain": {
"()": structlog.stdlib.ProcessorFormatter,
"processors": [
structlog.stdlib.ProcessorFormatter.remove_processors_meta,
structlog.dev.ConsoleRenderer(colors=False),
structlog.stdlib.ProcessorFormatter.remove_processors_meta,
structlog.dev.ConsoleRenderer(colors=False),
],
"foreign_pre_chain": pre_chain,
},
"colored": {
"()": structlog.stdlib.ProcessorFormatter,
"processors": [
extract_from_record,
structlog.stdlib.ProcessorFormatter.remove_processors_meta,
structlog.dev.ConsoleRenderer(colors=True),
extract_from_record,
structlog.stdlib.ProcessorFormatter.remove_processors_meta,
structlog.dev.ConsoleRenderer(colors=True),
],
"foreign_pre_chain": pre_chain,
},
Expand All @@ -507,8 +509,9 @@ logging.config.dictConfig({
"level": "DEBUG",
"propagate": True,
},
}
})
},
}
)
structlog.configure(
processors=[
structlog.stdlib.add_log_level,
Expand Down

0 comments on commit bb10cbb

Please sign in to comment.