Skip to content

Error-Handler 是用于捕获PHP项目运行期间的各类异常错误,支持通过monolog或者sentry进行错误上报.

License

Notifications You must be signed in to change notification settings

gaowei-space/error-handler

Repository files navigation

🌈 error-handler

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.

Installing

$ composer require gaowei-space/error-handler -vvv

Usage

1. sentry

$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);

2. monolog

$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);

Test

1. cp env file

cp examples/.env.example examples/.env

2. edit env file

SENTRY_DSN = "http:https://[email protected]/3"

3. run test code

php index.php examples/ErrorHandlerTest.php

Contributing

You can contribute in one of three ways:

  1. File bug reports using the issue tracker.
  2. 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.

License

MIT

About

Error-Handler 是用于捕获PHP项目运行期间的各类异常错误,支持通过monolog或者sentry进行错误上报.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages