Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor Cleanup of Structured Logging Module #4266

Merged
merged 17 commits into from
Nov 17, 2021
Merged

Conversation

nathaniel-may
Copy link
Contributor

@nathaniel-may nathaniel-may commented Nov 10, 2021

Description

1 - Cleaned up some of the code.

2- Fixed the adapter interface in here since post-cleanup it wasn't type checking. In the new system, the following logger call would have thrown a runtime exception before this change but is almost certainly present in the wild since it was found in our adapter tests:
logger.info("ran this sql: {}", sql)

Rather than re-implement every way a python logger could be called, I just make the std lib logger construct the message component of the log line and hand it back with a stringio buffer. <- this strategy did not work because the std lib logger does not use new-style string formatting, only old-style.

I dug into some logger libraries and found that this string formatting is really the only thing that *args is doing. Python prefers it this way so it can be done lazily which we are already doing via a function. I apply these arguments with new-style formatting via str::format to maintain compatibility with the former logbook logger.

Checklist

  • I have signed the CLA
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • I have updated the CHANGELOG.md and added information about my change

@nathaniel-may nathaniel-may mentioned this pull request Nov 11, 2021
26 tasks
@nathaniel-may nathaniel-may marked this pull request as draft November 12, 2021 00:21
@nathaniel-may nathaniel-may marked this pull request as ready for review November 12, 2021 00:21
Copy link
Member

@emmyoop emmyoop left a comment

Choose a reason for hiding this comment

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

Love how much cleaner it is.

@nathaniel-may nathaniel-may changed the base branch from feature/logging-phase-2 to main November 16, 2021 14:46
@nathaniel-may nathaniel-may mentioned this pull request Nov 16, 2021
5 tasks
Copy link
Member

@emmyoop emmyoop left a comment

Choose a reason for hiding this comment

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

The adapter fixes you implemented made me realize we should have generic adapter types, similar to what's in test_types.py for new adapters(or anyone inclined to make more updates than the few lines). Seems off to have new adapters use the old logging format.


fire_event(event)


def or_none(x: dict, key: str) -> Optional[Any]:
Copy link
Contributor

Choose a reason for hiding this comment

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

# this class shouldn't be createable, but we can't make it an ABC because of a mypy bug
if type(self).__name__ == 'AdapterEventBase':
raise Exception(
'attempted to create a message for AdapterEventBase which cannot be created'
Copy link
Contributor

Choose a reason for hiding this comment

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

Love the more explicit exception msg!

Copy link
Contributor

@iknox-fa iknox-fa left a comment

Choose a reason for hiding this comment

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

Just swap to using the built-in get method on those dicts and 👍

@nathaniel-may
Copy link
Contributor Author

@emmyoop if I'm understanding you correctly, I think that's exactly what we have already with the subclasses of types.py::AdapterEventBase. Do you mean something different than that?

Copy link
Contributor

@iknox-fa iknox-fa left a comment

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants