[php] 错误接管类

自己弄的一个错误接管类:

<?php

//----------------------------------
// Leephp 错误接管类
// 2017-07-06
// PengchongLee
//----------------------------------

 // error_reporting — 设置应该报告何种 PHP 错误
 error_reporting(0);

class Erro
{
    public function __construct()
    {
        $this->iserr();
    }
    public function iserr()
    {
        // set_exception_handler — 设置用户自定义的异常处理函数
        set_exception_handler([$this,‘ex‘]);

        // set_error_handler — 设置用户自定义的错误处理函数
        set_error_handler([$this,‘err‘]);

        // register_shutdown_function — 注册一个会在php中止时执行的函数
        register_shutdown_function( [ $this,‘last_error‘ ]);
    }

    // 异常接管
    public function ex($ex)
    {
        // 获取错误异常信息
        $message = $ex->getMessage();
        // 获取错误异常代码
        $code    = $ex->getCode();
        // 获取错误异常文件
        $file    = $ex->getFile();
        // 获取错误异常文件行数
        $line    = $ex->getLine();
    }

    // 错误接管
    public function err( $code, $message,$file ,$line )
    {
        // 记录日志
        $this->errlog( $code, $message,$file ,$line );
    }

    // 脚本结束前获取最后错误
    public function last_error()
    {
        // error_get_last — 获取最后发生的错误
        $last = error_get_last();
        $this->errlog( $last[‘type‘],$last[‘message‘],$last[‘file‘],$last[‘line‘] );
    }

    // 错误信息收集并记录 (参数传输的顺序不一样,参数还不一样)
    public function errlog( $code, $message,$file ,$line )
    {
        // 拼接错误信息
        $errstr  =  date(‘Y-m-d h:i:s‘)."\r\n";
        $errstr .= ‘  错误级别:‘.$code."\r\n";
        $errstr .= ‘  错误信息:‘.$message."\r\n";
        $errstr .= ‘  错误文件:‘.$file."\r\n";
        $errstr .= ‘  错误行数:‘.$line."\r\n";
        $errstr .= "\r\n";

        // error_log — 发送错误信息到某个地方
        error_log($errstr,3,__DIR__.‘/error.log‘);
    }

}
时间: 2024-12-14 15:45:25

[php] 错误接管类的相关文章

错误的类文件:… 类文件具有错误的版本 52.0,应为 50.0

出现问题: 今天在pom.xml中引入了最新版本guava工具包,编译时报了如下错误: [ERROR] E:\workspace\report\src\main\java\indi\johnny\report\template\excel\ExcelXSSFStyle.java:[16,-1] 无法访问 com.google.common.base.Strings错误的类文件: com\google\common\base\Strings.class(com\google\common\base

错误: 在类 com.zs.container.CollectionData 中找不到主方法, 请将主方法定义为: public static void main(String[] args)

错误: 在类 com.zs.container.CollectionData 中找不到主方法, 请将主方法定义为: public static void main(String[] args) package com.zs.container; import java.util.ArrayList; import com.java.array.generator.CountingGenerator.String; import com.java.array.generator.CountingG

错误日志类C#

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace WisdomCity.Entitys { public static class ErrorLog { /// <summary> /// 创建日志文件 /// </summary> /// <pa

错误: 在类 Main 中找不到 main 方法, 请将 main 方法定义为: public static void main(String[] args) 否则 JavaFX 应用程序类必须扩展javafx.application.Application

错误: 在类 Main 中找不到 main 方法, 请将 main 方法定义为: public static void main(String[] args)否则 JavaFX 应用程序类必须扩展javafx.application.Application 出现这种错误的原因其中一种就是 导包时错把其他的String包导入,以至于找不到main(String[ ]  args) 原文地址:https://www.cnblogs.com/mibloom/p/9497357.html

Java SpringBoot全局错误处理类,返回标准结果

package demo.utils; import com.alibaba.fastjson.JSON; import demo.controller.ProductController; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.web.bind.annotation.ExceptionHandler; impor

【c++错误】类的语法错误 error c2533:constructors not allowed a return type(构造函数不允许返回一个类型)

今天编写类的程序的时候不小心把类后的分号忘写了,就出现上面的错误提示. 顺便复习下类的正确格式: class 类名 { public: //习惯上将公有类型放在前面,便于阅读 ……(外部接口) protected: …… (保护型成员) private: ……(私有成员) }; //这里的分号千万不能忘写,不然会出现错误error: 2533:constructors not allowed a return type

封装一个错误重试类

/// <summary> /// 错误重试处理 /// </summary> public static class RetryHandle { /// <summary> /// 重试 /// </summary> /// <param name="count">重试次数</param> /// <param name="actionFunc">执行方法</param>

错误:类Byte是公共的,应在名为Byte.java 的文件中声明public class Byte{}一个错误

解决:文件名是xyz,那你的这个类名也应该是xyz.

自定义错误日志记录类

引言 这是一个简单的自定义的错误日志记录类,这里我主要用于API接口开发中,APP移动端的入参记录 日志参数 /// <summary> /// 日志参数 /// </summary> public static class LogReq { /// <summary> /// 入参 /// </summary> public static string LogReqStr = ""; /// <summary> /// 加密