evolutionphp/exceptions

简单的PHP错误处理和记录器。

1.3 2024-01-18 16:20 UTC

This package is auto-updated.

Last update: 2024-09-18 17:39:56 UTC


README

简单的PHP错误处理和记录器。

安装

使用 Composer 将记录器安装到您的项目中

composer require evolutionphp/exceptions

初始化

  1. 初始化异常类
$exceptions = new \EvolutionPHP\Exceptions\Exceptions();
  1. 注册处理器。如果为真,脚本将在窗口中显示错误(适合调试),否则错误将被隐藏。
$exceptions->register(true);

记录器

这是可选的,您可以保存错误日志。有关记录器的参数,请参阅 SimpleLogger

$exceptions->add_logger([
	'path' => __DIR__.'/logs/',
	'level' => 1
]);

调用实例

如果您已经初始化了异常类,则可以调用一个实例

$instance = \EvolutionPHP\Exceptions\Exceptions::instance();
//Set status header
$instance->set_status_header(500);

//Write log message
$instance->write_log('error','This is error message');

//Check if script is working under command line
if($instance->is_cli()){
	echo "You are in command line.\n";
}else{
	echo 'Welcome to our site.';
}

作者

此库最初由 CodeIgniter 3 开发,并由 Andres M 修改以供独立使用。