ErrorHandler is used to catch all php runtime errors and supports reporting to monolog or sentry.
Compared with the official instantiation method of sentry, it consumes less server resources because it instantiates sentry and reports the exception only when an exception is caught, which is why this package was born.
$ composer require gaowei-space/error-handler -vvv
$options = [
'report_level' => E_ALL,
'display_errors' => true, // prite errors
'handler' => 'sentry', // sentry or logger
'sentry_options' => [
'dsn' => 'http:https://[email protected]/3', // sentry website dsn
'environment' => 'test',
'sample_rate' => 1, // report rate, float range 0-1
'http_timeout' => 0.5,
],
];
ErrorHandler::init($options);
$logger = new Logger("php_errors");
$log_name = sprintf('php_errors_%s.log', date('Ymd'));
$logger->pushHandler(new StreamHandler("./log/" . $log_name, Logger::DEBUG, true, 0666));
$options = [
'report_level' => E_ALL, // error report level
'display_errors' => true, // prite errors
'handler' => 'logger', // sentry or logger
'logger' => $logger, // monolog loogger
];
ErrorHandler::init($options);
cp examples/.env.example examples/.env
SENTRY_DSN = "http:https://[email protected]/3"
php index.php examples/ErrorHandlerTest.php
You can contribute in one of three ways:
- File bug reports using the issue tracker.
- Answer questions or fix bugs on the issue tracker.
The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines.
MIT