2017 © Pedro Peláez
 

library php-errors

重写PHP错误处理程序,捕获所有PHP运行时错误并支持通过设置日志器将错误日志记录到日志中。

image

php-errors/php-errors

重写PHP错误处理程序,捕获所有PHP运行时错误并支持通过设置日志器将错误日志记录到日志中。

  • Friday, June 2, 2017
  • by KomaBeyond
  • Repository
  • 1 Watchers
  • 1 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

php-errors

PHP错误处理组件,可捕获PHP运行时的所有错误,通过设置错误报告级别及日志记录器,将PHP运行时的错误信息记录到日志中。 日志记录接口需遵守 prs-0 规范。支持通过设置 displayErrors 参数为 true 将错误信息打印到页面上。
通过推荐的 php.ini 配置来初始化 PHP 环境,再这之后的所有错误信息交给 php-errors 组件即可。  , (*1)

推荐 php.ini 配置(dev & pro)

display_errors = Off
display_startup_errors = Off
log_errors = On
error_log = 错误日志记录位置(绝对路径,也可以设置为 syslog,将日志打印到系统日志中)
error_reporting = E_ALL & E_STRICT

//php-fpm 环境下还应该设置 php-fpm 的配置,如下:通常位于 /path/to/fpm/pool.d/www.conf
catch_workers_output = yes

上述设置中的 error_log 文件位置仅仅作为备用日志文件地址,当没有设置日志记录器时,日志默认会被填充到该位置(推荐设置日志记录器)。

install

{
    "require": {
        "php-errors/php-errors": "~1.0"
    }
}

使用

$baseDir = dirname(__DIR__);
require $baseDir.'/vendor/autoload.php';

$errorHandler = \PHPErrors\PHPErrors::enable(E_ALL, true);

//以下代码可选,用来设置日志记录器(推荐这么做)
$logger = new \Monolog\Logger("test");
$logger->pushHandler(new \Monolog\Handler\StreamHandler(__DIR__."/test.log"));
$errorHandler->setLogger($logger);

建议   

应用代码中对于应用异常处理应通过 try/catch 代码块来捕获,否则异常会被 php-errors 捕获并记录到日志中。, (*2)

The Versions

02/06 2017

dev-master

9999999-dev

重写PHP错误处理程序,捕获所有PHP运行时错误并支持通过设置日志器将错误日志记录到日志中。

  Sources   Download

MIT

The Requires

 

The Development Requires

by Koma

02/06 2017

v1.1.0

1.1.0.0

重写PHP错误处理程序,捕获所有PHP运行时错误并支持通过设置日志器将错误日志记录到日志中。

  Sources   Download

MIT

The Requires

 

The Development Requires

by Koma

02/06 2017

v1.0.3

1.0.3.0

重写PHP错误处理程序,捕获所有PHP运行时错误并支持通过设置日志器将错误日志记录到日志中。

  Sources   Download

MIT

The Requires

 

The Development Requires

by Koma

01/06 2017

v1.0.2

1.0.2.0

重写PHP错误处理程序,捕获所有PHP运行时错误并支持通过设置日志器将错误日志记录到日志中。

  Sources   Download

MIT

The Requires

 

The Development Requires

by Koma

01/06 2017

v1.0.1

1.0.1.0

重写PHP错误处理程序,捕获所有PHP运行时错误并支持通过设置日志器将错误日志记录到日志中。

  Sources   Download

MIT

The Requires

 

The Development Requires

by Koma

31/05 2017

v1.0.0

1.0.0.0

重写PHP错误处理程序,捕获所有PHP运行时错误并支持通过设置日志器将错误日志记录到日志中。

  Sources   Download

MIT

The Requires

 

The Development Requires

by Koma