国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Telescope 應用調試工具

Telescope 應用調試工具


Laravel Telescope

簡介

Larave Telescope 是 Laravel 框架的優(yōu)雅調試助手。Telescope 可深入了解進入應用程序的請求、異常、日志條目、數(shù)據(jù)庫查詢、排隊作業(yè)、郵件、通知、緩存操作、計劃任務、變量轉儲等。Telescope 是您本地 Laravel 開發(fā)環(huán)境的絕佳伴侶。

1.png

安裝

你可以使用 Composer 在 Laravel 項目中安裝 Telescope 擴展:

composer require laravel/telescope

安裝 Telescope 后,可以在 Artisan 使用 telescope:install 命令來配置擴展實例。安裝 Telescope 后,還應運行 migrate 命令:

php artisan telescope:install

php artisan migrate

更新 Telescope

更新 Telescope 時,您應該重新配置加載 Telescope 實例:

php artisan telescope:publish

僅在特定環(huán)境中安裝

如果您打算僅使用 Telescope 來協(xié)助您的本地開發(fā)??梢允褂?--dev 標志安裝 Telescope:

composer require laravel/telescope --dev

運行 telescope:install 后,您應該從 app 配置文件中刪除 TelescopeServiceProvider 服務提供注冊。相反,在 AppServiceProviderregister 方法中手動注冊服務:

use Laravel\Telescope\TelescopeServiceProvider;
/**
 * 注冊應用服務。
 *
 * @return void
 */public function register(){ 
    if ($this->app->isLocal()) {    
        $this->app->register(TelescopeServiceProvider::class);  
        }
     }

定制數(shù)據(jù)遷移

如果您不打算使用 Telescope 的默認遷移,則應該在 AppServiceProviderregister 方法中調用 Telescope::ignoreMigrations 方法。您可以使用 php artisan vendor:publish --tag=telescope-migrations 命令導出默認遷移。

配置

使用 Telescope,其主要配置文件將位于 config/telescope.php。此配置文件允許您配置監(jiān)聽程序選項,每個配置選項都包含其用途說明,因此請務必徹底瀏覽此文件。

如果需要,您可以使用 enabled 配置選項完全禁用 Telescope 的數(shù)據(jù)收集:

'enabled' => env('TELESCOPE_ENABLED', true),

數(shù)據(jù)修改

有了數(shù)據(jù)修改,telescope_entries 表可以非??焖俚乩鄯e記錄。為了緩解這個問題,你應該使用 Artisan 每天運行 telescope:prune 命令:

$schedule->command('telescope:prune')->daily();

默認情況下,將獲取超過 24 小時的所有數(shù)據(jù)。在調用命令時可以使用 hours 選項來確定保留 Telescope 數(shù)據(jù)的時間。例如,以下命令將刪除 48 小時前創(chuàng)建的所有記錄:

$schedule->command('telescope:prune --hours=48')->daily();

儀表板授權

Telescope 在 /telescope 處顯示儀表板。默認情況下,您只能在 本地 環(huán)境中訪問此儀表板。在你的 app/Providers/TelescopeServiceProvider.php 文件中,有一個 gate 方法。此授權能控制在 非本地 環(huán)境中對 Telescope 的訪問。您可以根據(jù)需要隨意修改此權限限制以對 Telescope 安裝和訪問:

/**
 * 註冊 Telescope Gate。
 *
 * 使用 Gate 決定誰可以在非本地環(huán)境中訪問 Telescope。
 *
 * @return void
 */
 protected function gate(){
     Gate::define('viewTelescope', function ($user) { 
            return in_array($user->email, [     
                   'taylor@laravel.com',      
                     ]);   
                 });
              }

過濾

單項過濾

您可以通過在 TelescopeServiceProvider 中注冊的 filter 回調來過濾 Telescope 記錄的數(shù)據(jù)。默認情況下,此回調會記錄 本地 環(huán)境中的所有數(shù)據(jù)以及所有其他環(huán)境中的異常、進程中斷、計劃任務和帶有受監(jiān)控標記的數(shù)據(jù):

/**
 * 注冊應用服務。
 *
 * @return void
 */
 public function register(){ 
    $this->hideSensitiveRequestDetails();    
    Telescope::filter(function (IncomingEntry $entry) {     
       if ($this->app->isLocal()) {       
            return true;   
               }   
       return $entry->isReportableException() ||            
       $entry->isFailedJob() ||            
       $entry->isScheduledTask() ||            
       $entry->hasMonitoredTag();    
       });
    }

批量過濾

雖然 filter 回調過濾單個條目的數(shù)據(jù),但您可以使用 filterBatch 方法注冊一個回調,該回調過濾給定請求或控制臺命令的所有數(shù)據(jù)。如果回調返回 true ,則所有數(shù)據(jù)都由 Telescope 記錄:

use Illuminate\Support\Collection;
/**
 * 注冊應用服務。
 *
 * @return void
 */
 public function register(){ 
    $this->hideSensitiveRequestDetails();    
    Telescope::filterBatch(function (Collection $entries) {  
          if ($this->app->isLocal()) {        
              return true;      
                }      
           return $entries->contains(function ($entry) {    
                 return $entry->isReportableException() ||                
                 $entry->isFailedJob() ||                
                 $entry->isScheduledTask() ||                
                 $entry->hasMonitoredTag();            
                 });    
              });
          }

可用的監(jiān)聽

當在控制臺執(zhí)行命令或處理請求時,Telescope 監(jiān)聽器會收集應用程序數(shù)據(jù)。您可以在 config/telescope.php 配置文件中自定義要啟用監(jiān)聽項的列表:

'watchers' => [
    Watchers\CacheWatcher::class => true,    
    Watchers\CommandWatcher::class => true,   
     ...
   ],

一些監(jiān)聽器還允許您提供其他自定義選項:

'watchers' => [ 
   Watchers\QueryWatcher::class => [    
       'enabled' => env('TELESCOPE_QUERY_WATCHER', true),      
         'slow' => 100,
        ],  
       ...
    ],

緩存監(jiān)聽

當緩存鍵被命中、遺漏、更新和遺忘時,緩存監(jiān)聽器會記錄數(shù)據(jù)。

命令監(jiān)聽

只要執(zhí)行 Artisan 命令,命令監(jiān)聽器就會記錄參數(shù)、選項、退出代碼和輸出。如果您想排除監(jiān)聽器記錄的某些命令,您可以在 config/telescope.php 文件的 ignore 選項中指定命令:

'watchers' => [ 
   Watchers\CommandWatcher::class => [   
        'enabled' => env('TELESCOPE_COMMAND_WATCHER', true),   
             'ignore' => ['key:generate'],   
         ],   
       ...
   ],

數(shù)據(jù)監(jiān)聽

數(shù)據(jù)監(jiān)聽器在 Telescope 中記錄并顯示您的數(shù)據(jù)變量。使用 Laravel 時,可以使用全局 dump 函數(shù)輸出變量。必須在瀏覽器中打開數(shù)據(jù)監(jiān)聽器選項卡,才能進行輸出變量,否則監(jiān)聽器將忽略此次輸出。

事件監(jiān)聽

事件監(jiān)聽器記錄應用程序調度的任何事件的有效負載、監(jiān)聽器和廣播數(shù)據(jù)。事件監(jiān)聽器忽略了 Laravel 框架的內部事件。

異常監(jiān)聽

異常監(jiān)聽器記錄應用程序引發(fā)的任何可報告異常的數(shù)據(jù)和堆棧跟蹤。

Gate 監(jiān)聽

Gate 監(jiān)聽器記錄您的應用程序的 Gate 和策略檢查的數(shù)據(jù)和結果。如果您希望將某些能力排除在監(jiān)聽器的記錄之外,您可以在 config/telescope.php 文件的 ignore_abilities 選項中指定它們:

'watchers' => [ 
   Watchers\GateWatcher::class => [  
         'enabled' => env('TELESCOPE_GATE_WATCHER', true),        
         'ignore_abilities' => ['viewNova'],   
        ],    
       ...
    ],

進程監(jiān)聽

進程監(jiān)聽器記錄應用程序分派的任何作業(yè)的數(shù)據(jù)和狀態(tài)。

日志監(jiān)聽

日志監(jiān)視器記錄應用程序寫入的任何日志的日志數(shù)據(jù)。

郵件監(jiān)聽

郵件監(jiān)視器允許您查看電子郵件的瀏覽器內預覽及其相關數(shù)據(jù)。您也可以將該電子郵件下載為 .eml 文件。

模型監(jiān)聽

只要調度了模型的 create、updated、restoreddeleted 事件,模型觀察器就會記錄模型更改。您可以通過監(jiān)聽器的 events 選項指定應記錄哪些模型事件:

'watchers' => [
    Watchers\ModelWatcher::class => [   
         'enabled' => env('TELESCOPE_MODEL_WATCHER', true),        
         'events' => ['eloquent.created*', 'eloquent.updated*'],   
       ],   
      ...
   ],

消息通知監(jiān)聽

消息通知監(jiān)聽器記錄您的應用程序發(fā)送的所有通知。如果通知觸發(fā)了電子郵件并且您啟用了郵件監(jiān)聽器,則電子郵件也可以在郵件監(jiān)視器屏幕上進行預覽。

數(shù)據(jù)查詢監(jiān)聽

數(shù)據(jù)查詢監(jiān)聽器記錄應用程序執(zhí)行的所有查詢的原始 SQL、綁定和執(zhí)行時間。觀察者還將任何慢于 100 毫秒的查詢標記為 slow。您可以使用觀察者的 slow 選項自定義慢查詢閾值:

'watchers' => [
    Watchers\QueryWatcher::class => [     
       'enabled' => env('TELESCOPE_QUERY_WATCHER', true),        
       'slow' => 50,    
      ],   
     ...
  ],

Redis 監(jiān)聽

必須啟用 Redis 事件才能使 Redis 監(jiān)聽器正常運行。您可以通過在 app/Providers/AppServiceProvider.php 文件的 boot 方法中調用 Redis::enableEvents() 來啟用 Redis 事件。

Redis 監(jiān)聽器記錄您的應用程序執(zhí)行的所有 Redis 命令。如果您使用 Redis 進行緩存,Redis 監(jiān)聽器也會記錄緩存命令。

請求監(jiān)聽

請求監(jiān)聽器記錄與應用程序處理的任何請求相關聯(lián)的請求、標頭、會話和響應數(shù)據(jù)。您可以通過 size_limit (以 KB 為單位)選項限制響應數(shù)據(jù):

'watchers' => [ 
   Watchers\RequestWatcher::class => [   
        'enabled' => env('TELESCOPE_REQUEST_WATCHER', true),        
        'size_limit' => env('TELESCOPE_RESPONSE_SIZE_LIMIT', 64), 
       ],   
     ...
  ],

Schedule 監(jiān)聽

Schedule 監(jiān)聽器記錄應用程序運行的任何計劃任務的命令和輸出。

本文章首發(fā)在 LearnKu.com 網(wǎng)站上。