Skip to content

Commit de6ef4c

Browse files
committed
docs: add documentation for ignored_keys
1 parent c68cd90 commit de6ef4c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,33 @@ This will cause all logs to have the `trace_id=123` pair regardless of including
218218

219219
> Note, the defaults object uses format strings as values. This allows for variables templating. See "Aliases" guide for more information.
220220
221+
**Exclude ignored keys**
222+
223+
Sometimes log records include fields that you don't want in your output.
224+
This often happens when other libraries or frameworks add extra keys to the `LogRecord` that are not relevant to your log format.
225+
226+
You can explicitly exclude unwanted keys by using the `ignored_keys` parameter.
227+
228+
```py
229+
import logging
230+
from logfmter import Logfmter
231+
232+
formatter = Logfmter(
233+
keys=["at"],
234+
mapping={"at": "levelname"},
235+
datefmt="%Y-%m-%d",
236+
ignored_keys=["color_message"],
237+
)
238+
239+
handler = logging.StreamHandler()
240+
handler.setFormatter(formatter)
241+
242+
logging.basicConfig(handlers=[handler])
243+
244+
logging.info("Started server process [%s]", 97819, extra={"color_message": "Started server process [%d]"})
245+
# at=INFO msg="Started server process [97819]"
246+
```
247+
221248
## Extension
222249

223250
You can subclass the formatter to change its behavior.

0 commit comments

Comments
 (0)