zoukankan      html  css  js  c++  java
  • php 错误日志 抛出异常

    <?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())." ";
    $errstr .= '错误级别'.$type." ";
    $errstr .= ' 错信息'.$msg." ";
    $errstr .= ' 错误文件'.$file." ";
    $errstr .= ' 错误行'.$line;
    $errstr.=' ';
    error_log($errstr,3,'err.log');
    }
    }

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

  • 相关阅读:
    沉痛的一天
    PowerBuilder之5年经验谈(一之1)--PB对Unicode的支持
    C# Client API for Sphinx (support to 0.99)
    F#学习笔记基本类型
    F#学习笔记方法
    接口串联
    eclipse 中如何设置注释?
    软件测试过程中手机截屏
    Postan中执行接口时使用JSON数据,那么什么是 JSON?
    MySQL使用dump备份以及恢复备份
  • 原文地址:https://www.cnblogs.com/ayanboke/p/11026467.html
Copyright © 2011-2022 走看看