[GH-ISSUE #1741] How to get private variables from exception? #731

Closed
opened 2026-03-04 02:17:28 +03:00 by kerem · 1 comment
Owner

Originally created by @jokaorgua on GitHub (Aug 1, 2022).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1741

I'm using symfony-monolog-bundle 3.8.0 which uses monolog 3.1

I have an exception class

class EntityNotFoundException
{
   public function __construct(public mixed $entityId, public string $message, public int $code = 0){}
}

When I try to throw this exception in the console or any other place I get such a message

[2022-08-01T07:48:42.340497+00:00] [PID: 267257] console.CRITICAL: Error thrown while running command "test". Message: "Entity is not found" {"exception":"[object] (App\\Model\\EntityNotFoundException(code: 0): Entity is not found at .....:30)","command":"test","message":"Entity is not found"} [call:Symfony\Component\Console\EventListener\ErrorListener:48]

So the question is: how to get the id $entityId ? I want the "exception" field to be expanded and show all the private or public variables. I've tried to add JsonSerializable implementation to the exception but that didn't help

Need some advice. Thanks

Originally created by @jokaorgua on GitHub (Aug 1, 2022). Original GitHub issue: https://github.com/Seldaek/monolog/issues/1741 I'm using symfony-monolog-bundle 3.8.0 which uses monolog 3.1 I have an exception class ```php class EntityNotFoundException { public function __construct(public mixed $entityId, public string $message, public int $code = 0){} } ``` When I try to throw this exception in the console or any other place I get such a message ``` [2022-08-01T07:48:42.340497+00:00] [PID: 267257] console.CRITICAL: Error thrown while running command "test". Message: "Entity is not found" {"exception":"[object] (App\\Model\\EntityNotFoundException(code: 0): Entity is not found at .....:30)","command":"test","message":"Entity is not found"} [call:Symfony\Component\Console\EventListener\ErrorListener:48] ``` So the question is: how to get the id $entityId ? I want the "exception" field to be expanded and show all the private or public variables. I've tried to add JsonSerializable implementation to the exception but that didn't help Need some advice. Thanks
kerem 2026-03-04 02:17:28 +03:00
  • closed this issue
  • added the
    Support
    label
Author
Owner

@Seldaek commented on GitHub (Aug 2, 2022):

That's right, exceptions are just serialized as their message and stack trace. If you need more info I'd recommend passing it to the log's context directly.

<!-- gh-comment-id:1202407062 --> @Seldaek commented on GitHub (Aug 2, 2022): That's right, exceptions are just serialized as their message and stack trace. If you need more info I'd recommend passing it to the log's context directly.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#731
No description provided.