Skip to content

Commit

Permalink
feat: edit md
Browse files Browse the repository at this point in the history
  • Loading branch information
gaowei committed Jul 3, 2022
1 parent 6343e88 commit 5b56045
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 28 deletions.
47 changes: 19 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
# 🎯 Error-Handler
[中文](https://github.com/gaowei-space/error-handler/blob/main/README.md) | [English](https://github.com/gaowei-space/error-handler/blob/main/README_EN.md)

![GitHub branch checks state](https://img.shields.io/github/checks-status/gaowei-space/error-handler/main)
[![Latest Release](https://img.shields.io/github/v/release/gaowei-space/error-handler)](https://github.com/gaowei-space/error-handler/releases)
![StyleCI build status](https://github.styleci.io/repos/496875473/shield)
[![PHP Version](https://img.shields.io/packagist/php-v/gaowei-space/error-handler)](https://www.php.net/)
[![License](https://img.shields.io/github/license/gaowei-space/error-handler)](https://github.com/gaowei-space/error-handler/LICENSE)

[Error-Handler](https://github.com/gaowei-space/error-handler) is used to catch all php runtime errors and supports reporting to monolog or sentry.
[Error-Handler](https://github.com/gaowei-space/error-handler) 是用于捕获PHP项目运行期间的各类异常错误,支持通过**monolog**或者**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.
> 与官方的sentry加载方式相比,该包只在捕获到异常时才进行实例化并报告异常,所以消耗的服务器资源更少,这也是这个包诞生的原因。

## Installing
## 安装

```shell
composer require gaowei-space/error-handler
```

## Usage
## 使用

### 1. sentry
```php
Expand All @@ -34,8 +35,8 @@ $options = [
];
ErrorHandler::init($options);
```
- [sentry doc](https://docs.sentry.io/platforms/php/)
- [sentry options](https://docs.sentry.io/platforms/php/configuration/options/)
- [sentry 文档](https://docs.sentry.io/platforms/php/)
- [sentry 参数配置](https://docs.sentry.io/platforms/php/configuration/options/)


### 2. monolog
Expand All @@ -52,30 +53,30 @@ $options = [
ErrorHandler::init($options);
```

## Test
## 测试

### 1. install develop packages
### 1. 安装开发扩展包
```
composer require gaowei-space/error-handler --dev
```

### 2. cp env file
### 2. 复制配置文件
```
cp examples/.env.example examples/.env
```
### 3. edit env file
### 3. 编辑配置文件
```
SENTRY_DSN = "http:https://[email protected]/3"
```
### 4. run examples
### 4. 运行测试代码
```php
// monolog
php examples/Monolog.php
// sentry
php examples/Sentry.php
```

## Sentry initialization time-consuming comparison
## 与Sentry官方实例化进行对比如下
```
$options = [
'report_level' => E_ALL, // error report level
Expand All @@ -89,22 +90,12 @@ $options = [
],
];
Self:
ErrorHandler::init($options); // time consuming: 0.001616
本扩展包:
ErrorHandler::init($options); // 耗时: 0.001616
Sentry:
\Sentry\init($options['sentry_options']); // time consuming: 0.146600
Sentry 官方:
\Sentry\init($options['sentry_options']); // 耗时: 0.146600
```

## Contributing

You can contribute in one of three ways:

1. File bug reports using the [issue tracker](https://github.com/gaowei-space/error-handler/issues).
2. Answer questions or fix bugs on the [issue tracker](https://github.com/gaowei-space/error-handler/issues).

_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
## 授权许可
本项目采用 MIT 开源授权许可证,完整的授权说明已放置在 [LICENSE](https://github.com/gaowei-space/error-handler/blob/main/LICENSE) 文件中。
111 changes: 111 additions & 0 deletions README_EN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# 🎯 Error-Handler
[中文](https://github.com/gaowei-space/error-handler/blob/main/README.md) | [English](https://github.com/gaowei-space/error-handler/blob/main/README_EN.md)

![GitHub branch checks state](https://img.shields.io/github/checks-status/gaowei-space/error-handler/main)
[![Latest Release](https://img.shields.io/github/v/release/gaowei-space/error-handler)](https://github.com/gaowei-space/error-handler/releases)
![StyleCI build status](https://github.styleci.io/repos/496875473/shield)
[![PHP Version](https://img.shields.io/packagist/php-v/gaowei-space/error-handler)](https://www.php.net/)
[![License](https://img.shields.io/github/license/gaowei-space/error-handler)](https://github.com/gaowei-space/error-handler/LICENSE)

[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.

## Installing

```shell
composer require gaowei-space/error-handler
```

## Usage

### 1. sentry
```php
$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);
```
- [sentry doc](https://docs.sentry.io/platforms/php/)
- [sentry options](https://docs.sentry.io/platforms/php/configuration/options/)


### 2. monolog
```php
$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);
```

## Test

### 1. install develop packages
```
composer require gaowei-space/error-handler --dev
```

### 2. cp env file
```
cp examples/.env.example examples/.env
```
### 3. edit env file
```
SENTRY_DSN = "http:https://[email protected]/3"
```
### 4. run examples
```php
// monolog
php examples/Monolog.php
// sentry
php examples/Sentry.php
```

## Sentry initialization time-consuming comparison
```
$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
```

## Contributing

You can contribute in one of three ways:

1. File bug reports using the [issue tracker](https://github.com/gaowei-space/error-handler/issues).
2. Answer questions or fix bugs on the [issue tracker](https://github.com/gaowei-space/error-handler/issues).

_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

0 comments on commit 5b56045

Please sign in to comment.