Skip to content

Normalize exceptions in SyslogJsonFormatter log context#2060

Open
kayjoosten wants to merge 1 commit into
mainfrom
feature/issue-2055-exception-log-context
Open

Normalize exceptions in SyslogJsonFormatter log context#2060
kayjoosten wants to merge 1 commit into
mainfrom
feature/issue-2055-exception-log-context

Conversation

@kayjoosten

Copy link
Copy Markdown
Contributor

Summary

  • SyslogJsonFormatter::normalizeRecord() overrode Monolog's normalization pipeline and passed $record->context/$record->extra straight to JSON encoding without ever calling $this->normalize(...).
  • Every logged exception is stored raw as context['exception'] = $exception. json_encode() on a plain PHP object only serializes public properties, so EngineBlock_Exception-based exceptions (which declare 5 unused public props: sessionId, userId, spEntityId, idpEntityId, description) logged as {"sessionId":null,"userId":null,"spEntityId":null,"idpEntityId":null,"description":null} instead of class/message/code/file — making production logs useless for debugging.
  • Fix: run context/extra through $this->normalize(...) (inherited from JsonFormatter, already handles Throwableclass/message/code/file via normalizeException()) before assembling the record array.

Test plan

  • New unit test SyslogJsonFormatterTest — verified it fails against the pre-fix code (null instead of exception class) and passes post-fix
  • phpunit --testsuite=eb4/unit/integration/functional — all pass
  • phpcs, phpmd, docheader — clean
  • Behat default suite — 300 scenarios / 5557 steps pass
  • Live end-to-end: hit /api/connections on the running dev container with an invalid payload, tailed application.log, confirmed context.exception now contains class/message/code/file/previous

Closes #2055

Why is this change needed?
Prior to this change, SyslogJsonFormatter::normalizeRecord() bypassed
Monolog's normalization pipeline, passing $record->context/extra
straight to JSON encoding without ever calling $this->normalize(...).
Every logged exception is stored as a raw object under
context['exception']. PHP's json_encode() on a plain object only
serializes public properties, so instead of class/message/code/file,
EngineBlock_Exception-based exceptions logged as
{"sessionId":null,"userId":null,"spEntityId":null,"idpEntityId":null,
"description":null} — its five unused public properties — making
production exception logs useless for debugging.

How does it address the issue?
This change runs context and extra through $this->normalize(...)
(inherited from JsonFormatter) before assembling the record array, so
Throwable instances are converted via normalizeException() into their
proper class/message/code/file representation, matching pre-7.2
behavior.

#2055
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.

Engine 7.2 doesn't output exception data in logs

1 participant