-
Notifications
You must be signed in to change notification settings - Fork 5
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
Split core functionality and support orjson and msgspec #9
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced Apr 27, 2024
Closed
nhairs
changed the title
Split core functionality and support orjson
Split core functionality and support orjson and msgspec
May 3, 2024
nhairs
commented
May 3, 2024
# dependencies = [] | ||
requires-python = ">=3.8" | ||
dependencies = [ | ||
"typing_extensions", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I need to specify when to install this?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary of changes
Refactor common functionality into base module
This allows support multiple JSON encoders by having common functionality in
pythonjsonlogger.core
and then specialist formatters for each encoder.This is useful / needed, as not all JSON encoders support the
json.dumps
orjson.JSONEncoder
interfaces exactly. This enables us to support other JSON encoders like orjson and msgspec. In the future we may add support for other encoders.Better handling for custom styles
Achieved by mimicking
logging.Formatter.__init__
without actually calling it.A code snippet is worth
2**10
words:Rename
jsonlogger
module tojson
moduleCompatibility is maintained for the moment using
__getattr__
in__init__
.This is to enable more consistent naming of implementation specific module names. It also stops throwing around the word "logger" when this module only contains formatters.
Add support for orjson
orjson is a high performance (and more JSON spec correct) encoder. Given how many logging calls may occur - having a performant formatter available is important.
This includes ensuring it is covered in tests on appropriate platforms.
Note: orjson is not supported on pypy, and currently does not build for py313.
Add support for msgspec
msgspec is another library containing a high performance JSON encoder.
Note: msgspec is not supported on pypy, and currently does not build for py313.
Drops python 3.7 support
This is primary due do making use of the
validate
argument. I was also having issues with CI because python 3.7 is not available onmacos-latest
as of /recently/.Thinking more I could use
**kwargs
to capture the newer arguments, but also effort? Python 3.7 is soon going to be 2 years out of support (python 3.8 is schedule to be EOL this year).It's probably not a bad time to drop support since new major version. I'll still probably support bug fixes / security fixes for a while longer though (note to self - I'll need to make a
3.x
branch...).edit: 🤦 - I've already said python 3.7 is security fixes only so fine to drop support.