6
2

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 1 year has passed since last update.

Laravel でログ出力

Last updated at Posted at 2022-03-29

この記事の内容は、laravel8で動作確認しています。
とりあえず簡単にログ出力します。

Logファサードを使用してログに情報を書き込む

use Illuminate\Support\Facades\Log;

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

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class AppController extends Controller
{
    public function index()
    {
        Log::debug('message');
        return view('home');
    }
}

ログの出力先

デフォルト設定では、storage/logs/laravel.logに出力される。

エラーログの出力先を分ける

エラーログだけを日ごとの別ファイルに出力する設定。
config/logging.phpに下記のように設定を追加する。

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

         ・・・・・省略

        // 追加
        'errors' => [
            'driver' => 'daily',
            'path' => storage_path('logs/errors.log'),
            'level' => 'error',
        ],       
    ],



参考記事

6
2
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
6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?