python-logfmter icon indicating copy to clipboard operation
python-logfmter copied to clipboard

Exclude Keys

Open josheppinette opened this issue 3 years ago • 2 comments

Some third party libraries may make log calls with keys which we don't want to log. We should be able to exclude these keys from the final log line.

For example, when overriding uvicorn logging. The color_message key is currently printed (it is used by their custom color formatter). If we could exclude this key, then we could prevent the following output:

at=INFO msg="Started server process [97819]" color_message="Started server process [%d]"
at=INFO msg="Waiting for application startup."
at=INFO msg="Application startup complete."
at=INFO msg="Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)" color_message="Uvicorn running on %s://%s:%d (Press CTRL+C to quit)"

josheppinette avatar Feb 12 '22 23:02 josheppinette

It's an issue that for sure will come up as the default is to always include all keys. If nothing else a documentation note how it can be fixed with filters relatively easily would probably help many.

If that sound like the solution I may add a PR for that.

tapetersen avatar Jan 24 '25 13:01 tapetersen

@tapetersen I like that solution. Maybe we can add a section to guides.

josheppinette avatar Jan 24 '25 19:01 josheppinette

→ PR for ignore_keys in https://github.com/josheppinette/python-logfmter/pull/43

spaceone avatar Aug 29 '25 20:08 spaceone