[Error-Handler](https://github.com/gaowei-space/error-handler) 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
$options = [
'report_level' => E_ALL,
'display_errors' => true,
'handler' => 'sentry', // sentry or logger
'sentry_options' => [
'dsn' => 'http:https://[email protected]/3',
'environment' => 'test',
'sample_rate' => 1,
'http_timeout' => 0.5,
],
];
ErrorHandler::init($options);
$logger = new Logger("errors");
$logger->pushHandler(new StreamHandler(sprintf('%s/log/errors_%s.log', __DIR__, date('Ymd')), Logger::DEBUG, true, 0666));
$options = [
'report_level' => E_ALL,
'display_errors' => true,
'handler' => 'logger', // sentry or logger
'logger' => $logger,
];
ErrorHandler::init($options);
composer require gaowei-space/error-handler --dev
cp examples/.env.example examples/.env
SENTRY_DSN = "http:https://[email protected]/3"
// monolog
php examples/Monolog.php
// sentry
php examples/Sentry.php
$options = [
'report_level' => E_ALL, // error report level
'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,
],
];
Self:
ErrorHandler::init($options); // time consuming: 0.001616
Sentry:
\Sentry\init($options['sentry_options']); // time consuming: 0.146600
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