Skip to content

Tags: nhairs/python-json-logger

Tags

v4.0.0.dev0

Toggle v4.0.0.dev0's commit message
v4.0.0.dev0 release

v3.3.0

Toggle v3.3.0's commit message
Release 3.3.0

v3.2.1

Toggle v3.2.1's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Fix import pthonjsonlogger.jsonlogger (#33)

Fixes: #29

Although efforts were made for backwards compatibility using
`__getattr__` in `pythonjsonlogger/__init__.py`, this only worked if you
were doing `from pythonjsonlogger import jsonlogger`. When importing by
the full name `import pythonjsonlogger.jsonlogger` it it would fail to
locate the module file and thus not be able to produce a module spec
which then of course causes the import to fail.

We get around this by actually having a module that imports the names it
needs from the new locations.

### Test Plan

- Run unit tests

v3.2.0

Toggle v3.2.0's commit message
Release 3.2.0

v3.1.0

Toggle v3.1.0's commit message
Release 3.1.0

v3.1.0.rc3

Toggle v3.1.0.rc3's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Support missing rename fields and preserve order (#13)

Fixes #6
Fixes #7

Changes also prevent double renaming of fields.

## Test plan

Run tests

v3.1.0.rc2

Toggle v3.1.0.rc2's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Improve non-standard type encoding (#12)

This PR improves the JSON encoding of non-standard types by introducing
and using the `.defaults` module. The `.defaults` module adds helper
functions that can test and apply formatting for types not supported by
a given encoder.

Please note that in doing so, some outputs of the `JsonFormatter` have
changed. That said these changes return more "reasonable" results rather
the the original `str(o)` fallback.

For more detailed list of changes to the encoders see the CHANGELOG.

## Test Plan
Have added additional tests and now check for specific output.

v3.1.0.rc1

Toggle v3.1.0.rc1's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Split core functionality and support orjson and msgspec (#9)

## 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` or `json.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:

```python
from pythonjsonlogger.core import BaseJsonLogger

class CommaSupport(BaseJsonFormatter):
    def parse(self) -> list[str]:
        if isinstance(self._style, str) and self._style == ",":
            return self._fmt.split(",")
        return super().parse()

f = CommaSupport("message,asctime", style=",", validate=False)
```

### Rename `jsonlogger` module to `json` module

Compatibility 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](https://github.com/ijl/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](https://jcristharif.com/msgspec/index.html) 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`](https://docs.python.org/3/library/logging.html#formatter-objects)
argument. I was also having issues with CI because python 3.7 is not support on most "latest"

v3.0.1

Toggle v3.0.1's commit message
Release 3.0.1

v3.0.0

Toggle v3.0.0's commit message
Release 3.0.0