Skip to content

v3.1.0.rc3

Pre-release
Pre-release
Compare
Choose a tag to compare
@nhairs nhairs released this 18 May 06:53
· 14 commits to main since this release
1160ae8

3.1.0.rc3 - 2023-05-03

This splits common funcitonality out to allow supporting other JSON encoders. Although this is a large refactor, backwards compatibility has been maintained.

Added

  • .core - more details below.
  • .defaults module that provides many functions for handling unsupported types.
  • Orjson encoder support via .orjson.OrjsonFormatter with the following additions:
    • bytes are URL safe base64 encoded.
    • Exceptions are "pretty printed" using the exception name and message e.g. "ValueError: bad value passed"
    • Enum values use their value, Enum classes now return all values as a list.
    • Tracebacks are supported
    • Classes (aka types) are support
    • Will fallback on __str__ if available, else __repr__ if available, else will use __could_not_encode__
  • MsgSpec encoder support via .msgspec.MsgspecFormatter with the following additions:
    • Exceptions are "pretty printed" using the exception name and message e.g. "ValueError: bad value passed"
    • Enum classes now return all values as a list.
    • Tracebacks are supported
    • Classes (aka types) are support
    • Will fallback on __str__ if available, else __repr__ if available, else will use __could_not_encode__
    • Note: msgspec only supprts enum values of type int or str jcrist/msgspec#680

Changed

  • .jsonlogger has been moved to .json with core functionality moved to .core.
  • .core.BaseJsonFormatter properly supports all logging.Formatter arguments:
    • fmt is unchanged.
    • datefmt is unchanged.
    • style can now support non-standard arguments by setting validate to False
    • validate allows non-standard style arguments or prevents calling validate on standard style arguments.
    • default is ignored.
  • .json.JsonEncoder default encodings changed:
    • bytes are URL safe base64 encoded.
    • Exception formatting detected using BaseException instead of Exception. Now "pretty prints" the exception using the exception name and message e.g. "ValueError: bad value passed"
    • Dataclasses are now supported
    • Enum values now use their value, Enum classes now return all values as a list.
    • Will fallback on __str__ if available, else __repr__ if available, else will use __could_not_encode__
  • Renaming fields now preserves order (#7) and ignores missing fields (#6).

Deprecated

  • .jsonlogger is now .json
  • .jsonlogger.RESERVED_ATTRS is now .core.RESERVED_ATTRS.
  • .jsonlogger.merge_record_extra is now .core.merge_record_extra.

Removed

  • Python 3.7 support dropped
  • .jsonlogger.JsonFormatter._str_to_fn replaced with .core.str_to_object.