Skip to content

Honor exc_info_as_array for cached exception text - #95

Merged
nhairs merged 4 commits into
nhairs:mainfrom
AryanRG:fix/cached-exception-array
Oct 20, 2026
Merged

nhairs merged 4 commits into
nhairs:mainfrom
AryanRG:fix/cached-exception-array

Conversation

@AryanRG

@AryanRG AryanRG commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Fixes #89.

Apply exc_info_as_array to cached exception text as well as live tracebacks. Default string output and caller-provided exception fields stay unchanged.

This comes from the local SocketHandler reproduction in #89, not a production incident. The change keeps the configured JSON field type consistent without adding a new API.

The formatter regressions and full test suite pass, along with Black, Pylint and Pyrefly.

Prepared with AI assistance.

@nhairs nhairs left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks @AryanRG

Overall this looks simple enough to include. I've left some inline comments

Comment thread docs/changelog.md Outdated
- Replaced MyPy with Pyrefly for type checking

### Fixed
- `exc_info_as_array=True` now splits cached exception text into lines when a transported log record has no `exc_info` tuple.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Needs to reference issue

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added the link to #89.

Comment thread tests/test_formatters.py

@pytest.mark.parametrize("class_", ALL_FORMATTERS)
@pytest.mark.parametrize("exc_info_as_array", [False, True])
@pytest.mark.parametrize(

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Why do we parametrize this if it's only one value?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There are three message cases here: cached text, a string override, and a list override. I've added case names to make that clearer; the override cases check that caller-provided values still win.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

That makes more sense thanks

Comment thread tests/test_formatters.py
class_: type[BaseJsonFormatter],
exc_info_as_array: bool,
message: str | dict[str, Any],
) -> None:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This function could do with better comments

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added comments explaining the cached receiver state and what the override cases check.

Comment thread pyproject.toml Outdated
[project]
name = "python-json-logger"
version = "4.2.1.dev1"
version = "4.2.1.dev2"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

No need to update this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the version bump.

Comment thread docs/changelog.md Outdated

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Don't forget to add your name here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added, thanks!

@nhairs
nhairs merged commit 600e7a7 into nhairs:main Oct 20, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

exc_info_as_array is ignored for cached exception text after SocketHandler serialization

2 participants