Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Move logging to %-style formatting [#837] #1132

Merged
merged 12 commits into from
Aug 24, 2022
Merged

Conversation

pattisdr
Copy link
Contributor

@pattisdr pattisdr commented Aug 23, 2022

❗ Get up-to-date with main before merging, so we pick up any newly-added logs.

Purpose

The "f string" formatting we use across the majority of our logs make them not maskable. Update logging across the entire application to be a format we can mask and switch logging strategy to be Pii instead of NotPii.

There's a side benefit of using "%" formatting in that it is evaluated lazily and only calculated if the message is actually emitted.

Changes

  • Switches logging to %-style formatting
  • Increase the number of potential PII items that we mask
  • Mask if Pii instead of "don't mask if NotPii. If you want to mask something in the logs, it needs to be specifically wrapped in Pii

Checklist

  • Update CHANGELOG.md file
    • Merge in main so the most recent CHANGELOG.md file is being appended to
    • Add description within the Unreleased section in an appropriate category. Add a new category from the list at the top of the file if the needed one isn't already there.
    • Add a link to this PR at the end of the description with the PR number as the text. example: #1
  • Applicable documentation updated (guides, quickstart, postman collections, tutorial, fidesdemo, database diagram.
  • If docs updated (select one):
    • documentation complete, or draft/outline provided (tag docs-team to complete/review on this branch)
    • documentation issue created (tag docs-team to complete issue separately)
  • Good unit test/integration test coverage
  • This PR contains a DB migration. If checked, the reviewer should confirm with the author that the down_revision correctly references the previous migration before merging
  • The Run Unsafe PR Checks label has been applied, and checks have passed, if this PR touches any external services

Ticket

Fixes #837

@pattisdr pattisdr changed the title [Draft] Move logging to %-style formatting [#837] Move logging to %-style formatting [#837] Aug 23, 2022
@pattisdr pattisdr marked this pull request as ready for review August 23, 2022 20:25
@@ -97,7 +97,6 @@ disable=[
"import-outside-toplevel",
"invalid-name",
"line-too-long",
"logging-fstring-interpolation",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will keep us from using f-strings in our logs going forward.

Comment on lines 51 to +55

Don't mask numeric values as this can throw errors in consumers
format strings.
"""

if isinstance(parameter, (NotPii, Number)):
return parameter
Logging args must be specifically wrapped in Pii in order to mask.

return MASKED
"""
return MASKED if isinstance(parameter, Pii) else parameter
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This flips to mask if PII instead of "don't mask if not PII or it's a number"

…atting

# Conflicts:
#	CHANGELOG.md
#	src/fidesops/main.py
#	src/fidesops/ops/core/config.py
Copy link
Contributor

@sanders41 sanders41 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I caught them all last round, but saw a couple more }. I did a search this time and these look to be the last 2.

@sanders41 sanders41 merged commit 16c48d3 into main Aug 24, 2022
@sanders41 sanders41 deleted the fidesops_837_log_formatting branch August 24, 2022 00:52
sanders41 pushed a commit that referenced this pull request Sep 22, 2022
* Add a new Pii class and use it to wrap arguments not already wrapped with NonPii in those logs that are currently using %-style formatting.

* Switch logging formatting to %-style instead of f-string.

* Continue to address lingering f string instances, and wrap some arguments in Pii, such as raw exceptions.

* Remove NotPii class and update tests.

* Adjust errors made in %-style conversion.

* Remove accidental Pii on print statements, update some PII wrappings.

* Adjust string formatting of newly added log.

* Update Changelog.

* Fix missed closing curly brackets.

* Remove missed curly brackets.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update log formatting so they can be masked if needed
2 participants