You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
exc_info_as_array is ignored for cached exception text after SocketHandler serialization #89
JsonFormatter(exc_info_as_array=True) emits exc_info as a string, not an array, when a received LogRecord has cached exc_text but no exc_info tuple. This is a normal shape after Python's logging.handlers.SocketHandler serializes a record: it formats the exception into exc_text and clears exc_info before transport. The formatter honors the option when the tuple is present, so the same configured output field changes JSON type across that boundary.
Reproduction
importjsonimportloggingimportlogging.handlersimportpickleimportsysfrompythonjsonlogger.jsonimportJsonFormattertry:
raiseValueError("example")
exceptValueError:
record=logging.LogRecord("example", logging.ERROR, __file__, 1, "failed", (), sys.exc_info())
handler=logging.handlers.SocketHandler("localhost", 9020)
try:
packet=handler.makePickle(record) # Local serialization; no socket connection.finally:
handler.close()
received=logging.makeLogRecord(pickle.loads(packet[4:]))
result=json.loads(JsonFormatter(exc_info_as_array=True).format(received))
print(type(result["exc_info"]).__name__) # str; expected list
This locally generated payload is decoded only for the reproduction; it does not suggest unpickling untrusted network data.
I reproduced the mismatch on current main (d036e2d6) and tested a minimal local fix that splits cached text into lines only when exc_info_as_array=True, preserving default string behavior and caller-supplied overrides. The new regression fails against base, then passes with the fix for the JSON, orjson and msgspec formatters. The local full suite passed (239 tests), along with Black, Pylint and Pyrefly. No network listener or live transport deployment was exercised.
Would you welcome a focused PR for this behavior?
AI assistance disclosure: OpenAI Codex assisted with investigation, reproduction, patch drafting, and local testing. This issue does not certify personal review or legal rights for a future PR.
Without evidence of this affecting real use-cases I'm not sure if this is a situation I want to handle. Particularly as I would question why a modern application is encoding and transferring log records via the SocketHandler only to decode them and re-encode them.
That said, if the change is simple enough to maintain then I would consider a PR for it. If you want to open a PR I'll check it out.
Thanks @nhairs, opened #95 with the small cached-text fix. I only have the local reproduction, not a production use case. Default output and caller overrides are unchanged.
Activity
nhairs commentedon Oct 18, 2026
Hi @AryanRG,
Without evidence of this affecting real use-cases I'm not sure if this is a situation I want to handle. Particularly as I would question why a modern application is encoding and transferring log records via the SocketHandler only to decode them and re-encode them.
That said, if the change is simple enough to maintain then I would consider a PR for it. If you want to open a PR I'll check it out.
AryanRG commentedon Oct 18, 2026
Thanks @nhairs, opened #95 with the small cached-text fix. I only have the local reproduction, not a production use case. Default output and caller overrides are unchanged.
Honor exc_info_as_array for cached exception text (nhairs#95)