LoginSignup
13

More than 5 years have passed since last update.

Laravelのlogファイルを日付ごとに分ける

Last updated at Posted at 2017-12-23

概要

※Laravelの検証バージョン5.x系

Laravelでは、デフォルトではログファイルが一つしか生成されない。

ログの出力先

/app_name/storage/logs/laravel.log

これではログを見返す必要があるとき、追いづらいので、日付ごとに出力ファイルに分ける。

手順

設定ファイルの内容を変更する。

/app_name/config/app.php

デフォルト(変更前)の設定ファイルは以下の通り

return [

    'log' => env('APP_LOG', 'single'),

    'log_level' => env('APP_LOG_LEVEL', 'debug'),

    ],

];

変更後の設定ファイルは以下の通り

return [

    'log' => env('APP_LOG', 'daily'), // logファイルを日付ごとに出力

    'log_level' => env('APP_LOG_LEVEL', 'debug'), // logレベルdebug

    'log_max_files' => '31',  // dailyログの場合のlogファイルの保存期間

    ],

];

以上で設定は完了。

結果

日付ごとにlogファイルが出力されている。


/app_name/storage/logs/laravel-2017-10-20.log
/app_name/storage/logs/laravel-2017-10-21.log
/app_name/storage/logs/laravel-2017-10-22.log

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
13