0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Laravel:Debugbarを左からまとめる

Posted at

こんにちは。

Laravelのdebugbar便利ですよね。
ただ機能が多く、使いこなせてる気がしないのでここらで何ができるかまとめようと言う記事です。
*現状わかってないこともあるので分かり次第追記します。

スクリーンショット 2022-03-02 23.44.51.png

設定はこれで全てのはず。

debugbar.php
    'collectors' => [
        'phpinfo'         => true,  // Php version
        'messages'        => true,  // Messages
        'time'            => true,  // Time Datalogger
        'memory'          => true,  // Memory usage
        'exceptions'      => true,  // Exception displayer
        'log'             => true,  // Logs from Monolog (merged in messages if enabled)
        'db'              => true,  // Show database (PDO) queries and bindings
        'views'           => true,  // Views with their data
        'route'           => true,  // Current route information
        'auth'            => true,  // Display Laravel authentication status
        'gate'            => true,  // Display Laravel Gate checks
        'session'         => true,  // Display session data
        'symfony_request' => true,  // Only one can be enabled..
        'mail'            => true,  // Catch mail messages
        'laravel'         => true,  // Laravel version and environment
        'events'          => true,  // All events fired
        'default_request' => true,  // Regular or special Symfony request logger
        'logs'            => true,  // Add the latest log messages
        'files'           => true,  // Show the included files
        'config'          => true,  // Display config settings
        'cache'           => true,  // Display cache events
        'models'          => true,  // Display models
    ],

Messages

必須!ログの出力が確認できる。

\Log::info('Log::info()');
\Debugbar::info('Debugbar::info()');
logger()->info('logger()->info()');

スクリーンショット 2022-03-03 1.20.02.png

Timeline

時間計測ができる
処理が重い時に原因の切り分けができる。
Booting: laravel 起動時間
Application: 実際の処理時間<-ここの割合を見ることが多い

start_measure('key', 'keyで囲った処理');
// 時間測りたい処理
sleep(2);
stop_measure('key');
add_measure('最初からの経過時間', LARAVEL_START, microtime(true));

スクリーンショット 2022-03-03 1.18.47.png

Exceptions

エラーの詳細を表示してくれる。

try {
    throw new \Exception('エラー');
} catch(\Exception $e) {
    \Debugbar::addException($e);
}

スクリーンショット 2022-03-03 1.28.42.png

Request

リクエストの中身が見れる。
validationのデバッグで使えそう。

localhost/hoge?hoge=hogeeeeee
でアクセスした例
スクリーンショット 2022-03-03 1.31.38.png

Events

イベントの処理にかかった時間が出てくる。

スクリーンショット 2022-03-03 1.45.01.png

Views

表示しているbladeの詳細が出てくる。
渡しているパラメータのkeyは見れた。

hoge.blade.php
@includes('fuga', [
    'title' => 'fuga',
])
fuga.blade.php
{{ $title }}

スクリーンショット 2022-03-03 1.51.36.png

Route

routingの詳細が見れる。

スクリーンショット 2022-03-03 1.53.20.png

Queries

必須!処理の中で発行されたsqlが確認できる。
他にも実行時間がわかるので重いクエリやN+1の発見に役立つ。

queries.png
画像引用:Laravel Debugbarについて

Models

利用しているモデルとその数が出力される

Mails

よくわからない?
メール飛ばす時に確認します。

Logs

storage/logsファイルの中身を出してくれる。
ファイルの中身全てを出してくれるわけではない。

スクリーンショット 2022-03-03 2.12.45.png

Auth

認証周り?手元では常にnullなので、よくわからない。

Gate

Gateの確認を行なってくれるみたい。
よくわからない。

Cache

viewのキャッシュ情報が出てくる。
forgetボタンからキャッシュの削除が可能。*ログイン情報なども消える。

スクリーンショット 2022-03-03 2.28.35.png

Config

config/以下の設定をまとめて表示してくれている。

Session

session情報が確認できる。
flashやoldの値が確認できる。

スクリーンショット 2022-03-03 2.29.27.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?