symfony/symfony — pull request #10921 by nicolas-grekas (2014-05-16 21:33:18+00:00)
Title: [WIP] [Debug] UniversalErrorHandler

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

This is an early WIP, but I wanted to submit it to your eyes asap, to gather early feedback.
To me, the current ErrorHandler in the Debug component is not really usable as a generic standalone error handler component.

This proposed new class is a merge of my previous work on the subject (https://github.com/nicolas-grekas/Patchwork-Error-Logger/blob/master/class/Patchwork/PHP/InDepthErrorHandler.php) and recent improvements of error handling in Symfony's Debug\ErrorHandler.

The proposed goal is to build a class that can serve as a foundation for a standard error handler, shared with other projects and not only used by the FrameworkBundle.

UniversalErrorHandler provides five bit fields that control how errors are handled:

- thrownErrors: errors thrown as ContextErrorException
- loggedErrors: logged errors, when not @-silenced
- scopedErrors: errors thrown or logged with their local context
- tracedErrors: errors logged with their trace, only once for repeated errors
- screamedErrors: never @-silenced errors

Each error level can be logged by a dedicated PSR-3 logger object.
Throwing has a higher priority than logging. Screaming applies to both.
Non catchable errors that can be detected at shutdown time are logged when the scream bit field allows so.
Uncaught exceptions are logged as E_ERROR.
As errors have a performance cost, repeated errors are all logged, so that the developer
can see them and weight them as more important to fix than others of the same level.

The merge is no complete today, eg handling fatal errors and exceptions still need some work, but the main ideas I wanted to share are here I think.