| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace App\Exceptions;
- use App\Services\LogService;
- use Illuminate\Support\Facades\Auth;
- use Throwable;
- class Exception extends \Exception
- {
- public $type;
- public function __construct($message = "",$type='error', $code = 0, Throwable $previous = null)
- {
- parent::__construct($message, $code, $previous);
- $this->type=$type;
- $this->logging();
- }
- public function logging()
- {
- \Illuminate\Support\Facades\Log::info("抓取内存耗尽错误",debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT,5));
- if (substr($this->getFile(),-(strlen("FatalError.php")))==='FatalError.php'){
- \Illuminate\Support\Facades\Log::emergency("FPM内存耗尽",["user"=>Auth::id(),"param"=>request()]);
- }
- $exception=$this;
- list(
- $className,
- $functionName,
- $tracesAll
- )
- =(function()use($exception){
- $traces=method_exists($exception,'getTraceAsString')
- ?($exception->getTraceAsString()??'')
- :'';
- if(!$traces)return '';
- preg_match('/\#0.*?\: (.*?)(-\>|\:\:)(.*?)\(/', $traces, $result);
- return [$result[1]??'',$result[3]??'',$traces];
- })();
- LogService::log(
- $className,
- $functionName,
- ($exception->getMessage()??'')
- .'调用堆栈e:'.$tracesAll,
- Auth::id()??'',
- $this->type
- );
- }
- }
|