1
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?

Laravel9ログの出力

Posted at

Laravel9ログの出力

Laravelでログを保存する方法と出力方法を解説

環境

  • Laravel 9

ログの出力方法は2種類あります。

  • ログの保存(/storage/logs/laravel.log)して表示
  • ログを保存せずにターミナルで表示

ログの保存(/storage/logs/laravel.log)して表示の場合

/config/logging.phpに追記

/config/logging.php
'channels' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => ['single'],
            'ignore_exceptions' => false,
        ],

        'single' => [
            'driver' => 'single',
            'path' => storage_path('logs/laravel.log'), //<-変更
            'level' => env('LOG_LEVEL', 'debug'),
        ],
],

ログを保存せずにターミナルで表示の場合

/config/logging.phpに追記

config/logging.php
'stdout' => [
    'driver' => 'monolog',
    'handler' => StreamHandler::class,
    'with' => [
        'stream' => 'php://stdout',
    ],
],

.envに追記

.env
LOG_CHANNEL=stdout

ログの出力

ログレベル

Log::emergency($message);
Log::alert($message);
Log::critical($message);
Log::error($message);
Log::warning($message);
Log::notice($message);
Log::info($message);
Log::debug($message);

使用方法


use Illuminate\Support\Facades\Log;

    public function store(Request $request)
    {
        Log::info($request);
    }
1
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
1
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?