Explorar el Código

日志添加筛选条件 class method

ANG YU hace 5 años
padre
commit
5ede3a7bac

+ 12 - 1
app/Filters/LogFilters.php

@@ -13,7 +13,7 @@ class LogFilters
     protected $request;
     protected $queryBuilder;
     protected $filters = ['username', 'type', 'description',
-        'created_at_start', 'created_at_end', 'is_exception'];
+        'created_at_start', 'created_at_end', 'is_exception', 'class', 'method'];
     protected $array_filter;
 
     public function __construct(Request $request)
@@ -94,6 +94,17 @@ class LogFilters
         $this->queryBuilder->where("description", 'like', $description . '%');
     }
 
+    private function class($class)
+    {
+        $class = str_replace('\\', '\\\\', $class);
+        $this->queryBuilder->where("class", 'like', $class . '%');
+    }
+
+    private function method($method)
+    {
+        $this->queryBuilder->where("method", 'like', $method . '%');
+    }
+
     private function type($type)
     {
         $types = array_filter(preg_split('/[,, ]+/is', $type));

+ 33 - 0
database/migrations/2021_02_04_104419_add_class_created_at_index.php

@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddClassCreatedAtIndex extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('logs', function (Blueprint $table) {
+            //
+            $table->index(['class', 'created_at']);
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('logs', function (Blueprint $table) {
+            $table->dropIndex(['class', 'created_at']);
+        });
+    }
+}

+ 2 - 0
resources/views/maintenance/log/index.blade.php

@@ -75,6 +75,8 @@
                                 {'name': 'panic', 'value': 'panic'},
                                 {'name': 'fatal', 'value': 'fatal'}],},
                         {name: 'description', type: 'input', tip: '详情:可在两侧添加百分号(%)进行模糊搜索', placeholder: '详情'},
+                        {name: 'class', type: 'input', tip: '类名:可在两侧添加百分号(%)进行模糊搜索', placeholder: '类名'},
+                        {name: 'method', type: 'input', tip: '方法名:可在两侧添加百分号(%)进行模糊搜索', placeholder: '方法名'},
                         {name:'created_at_start',type:'dateTime',tip:'选择显示指定日期的起始时间,只选一个或者不选,则查询当天'},
                         {name:'created_at_end',type:'dateTime',tip:'选择显示指定日期的截止,只选一个或者不选,则查询当天'},
                         {name:'is_exception',type:'checkbox',tip:'仅显示异常', data: [{name: 'true', value: '仅显示异常'}]}