LD 5 лет назад
Родитель
Сommit
885f4fa115
2 измененных файлов с 29 добавлено и 0 удалено
  1. 27 0
      app/Exceptions/Exception.php
  2. 2 0
      app/Http/Controllers/TestController.php

+ 27 - 0
app/Exceptions/Exception.php

@@ -4,6 +4,8 @@
 namespace App\Exceptions;
 
 
+use App\Services\LogService;
+use Illuminate\Support\Facades\Auth;
 use Throwable;
 
 class Exception extends \Exception
@@ -13,5 +15,30 @@ class Exception extends \Exception
         {
             parent::__construct($message, $code, $previous);
             $this->type=$type;
+            $this->logging();
+        }
+        public function logging()
+        {
+            $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()??'')
+                .'调用堆栈:'.$tracesAll,
+                Auth::id()??'',
+                $this->type
+            );
         }
 }

+ 2 - 0
app/Http/Controllers/TestController.php

@@ -15,6 +15,7 @@ use App\Console\Commands\CreateOwnerReport;
 use App\Console\Commands\SyncWmsCommoditiesInformation;
 use App\Console\Commands\SyncWMSOrderTask;
 use App\Console\Commands\WasSyncWmsAsnInformation;
+use App\Exceptions\ErrorException;
 use App\Imports\OrderTrackingImport;
 use App\InventoryAccount;
 use App\LaborReport;
@@ -283,6 +284,7 @@ sql;
 
     function t1(Request $request)
     {
+        throw new ErrorException('eeeff');
         DB::connection('oracle')->update(DB::raw("update BAS_SKU set HAZARD_FLAG= 'N' where SKU= '13564151055'"));
 //        DB::connection('oracle')->update(DB::raw("UPDATE DOC_ORDER_HEADER SET notes = CASE WHEN notes IS NULL THEN '停运' ELSE  notes||',停运' END where ORDERNO in ('','SO190628000050','SO190628000001')"));
     }