Skip to content

Conversation

nicolas-grekas
Copy link
Member

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

@@ -67,13 +68,13 @@ public function onKernelException(GetResponseForExceptionEvent $event)
try {
$response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, true);
} catch (\Exception $e) {
$this->logException($exception, sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $e->getMessage()), false);
$this->logException($e, sprintf('Exception thrown when handling an exception (%s: %s at %s line %s)', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()), false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to add an optional $context argument to logException? That makes it possible to properly log in the 'exception' context. Besides of having a cleaner messages and cleaner code, it will be handled properly by monolog handlers.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the parent exception logged properly? In that is not the case, I prefer to see a smaller message or log both exceptions.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

My bad, I missed the first one. I still stand for "I prefer to see a smaller message" though. All the information passed to the message is located in the context as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

What about something as simple as this? The context should log the Exception and the formatters will properly format the logs for you. In case of the HTML formatter, this will be the basic exception information; Exception Class, Message and Trace.

// message is up for improvement
$this->logException($e, 'An Exception has been thrown when handling another Exception.', false);

Copy link
Member Author

Choose a reason for hiding this comment

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

IMO, this would wrongly aggregate all same log lines, where they should not. An uncaught double exception is important to caught, and rare. I'd keep the msg asis.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not too familiar with logging, but isn't that what the context is for? You could always put the actual exception class in the message, more than that would make it unreadable clutter.

Copy link
Member Author

Choose a reason for hiding this comment

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

I propose you do an other PR if you want, as that was not the prupose of this one (I did not change the message but for adding line+file info) :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I think this is starting to fall out of the scope of this PR.

@nicolas-grekas
Copy link
Member Author

Please note that this PR is not meant to be merged asis. The current code in 2.3 eats double-bounce exceptions, and this can be fixed by the added throw $e XOR checking for NullLogger. I implemented both so we can talk and decide what is the best.

@nicolas-grekas nicolas-grekas force-pushed the log-x branch 3 times, most recently from b892c6a to bdf6dde Compare February 24, 2015 17:34
@nicolas-grekas nicolas-grekas changed the title [HttpKernel] Make double-bounce exceptions visible [HttpKernel] Throw double-bounce exceptions Feb 24, 2015
@nicolas-grekas nicolas-grekas force-pushed the log-x branch 4 times, most recently from 89ce962 to c45ece9 Compare February 24, 2015 18:59
@nicolas-grekas
Copy link
Member Author

PR is now ready

@fabpot
Copy link
Member

fabpot commented Feb 25, 2015

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 0ebcf63 into symfony:2.3 Feb 25, 2015
fabpot added a commit that referenced this pull request Feb 25, 2015
This PR was merged into the 2.3 branch.

Discussion
----------

[HttpKernel] Throw double-bounce exceptions

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Commits
-------

0ebcf63 [HttpKernel] Throw double-bounce exceptions
@nicolas-grekas nicolas-grekas deleted the log-x branch March 1, 2015 10:11
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.

5 participants