首页 > Web开发 > 详细

php 错误日志 抛出异常

时间:2019-06-15 10:37:17      阅读:123      评论:0      收藏:0      [点我收藏+]

<?php

// ini_set(‘display_errors‘, ‘on‘);
// error_reporting(E_ALL|E_STRICT);

error_reporting(0);
// 错误异常类 错误接管
class App{
public function __construct(){
$this->iserr();
}

public function iserr(){
set_exception_handler([$this,‘ex‘]);
set_error_handler([$this,‘err‘]);
//脚本运行结束前调用rsf
register_shutdown_function([$this,‘rsf‘]);

}

public function rsf(){
$er = error_get_last();
if(in_array($er[‘type‘],[1,4,16])){
$this->errorlog($er[‘type‘],$er[‘message‘],$er[‘file‘],$er[‘line‘]);
}
}

/**
*异常接管
*/
public function ex($ex){
$msg = $ex->getMessage();
$type = $ex->getCode();
$file = $ex->getFile();
$line = $ex->getline();
// echo ‘类型:‘.$type.‘信息:‘.$msg.‘ 位置:‘.$file.‘ 错误行:‘.$line;
$this->errorlog($type,$msg,$file,$line);
}

/**
*获取错误信息
*/
public function err($type,$msg,$file,$line){
// echo ‘类型:‘.$type.‘信息:‘.$msg.‘ 位置:‘.$file.‘ 错误行:‘.$line;
$this->errorlog($type,$msg,$file,$line);
}


/**
*错误日志
*/
public function errorlog($type,$msg,$file,$line){
$errstr = date(‘Y-m-d H:i:s‘,time())."\r\n";
$errstr .= ‘错误级别‘.$type."\r\n";
$errstr .= ‘ 错信息‘.$msg."\r\n";
$errstr .= ‘ 错误文件‘.$file."\r\n";
$errstr .= ‘ 错误行‘.$line;
$errstr.=‘\r\n‘;
error_log($errstr,3,‘err.log‘);
}
}

new App();
// include (‘err.php‘);
echo $s;
// echo $app->iserr();
// throw new Exception("Error Processing Request", 500);

php 错误日志 抛出异常

原文:https://www.cnblogs.com/ayanboke/p/11026467.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!