LoginSignup
4
6

More than 5 years have passed since last update.

【Laravel】ログファイルを日別で作成する設定

Posted at

環境

CentOS: 7.4
PHP: 7.2
Laravel: 5.6

Laravel のログファイルを日別で作成する

Laravel のバージョンにもよるかもしれませんが、私の環境ではログがすべて laravel.log に追加されるようになっていました。
ログファイルの容量が増えてしまったりログが確認しづらいので、ログファイルを日別で作成するように設定します。

config/logging.phpLOG_CHANNELdaily に変更することで実現できます。

config/logging.php
<?php

use Monolog\Handler\StreamHandler;

return [

    /*
    |--------------------------------------------------------------------------
    | Default Log Channel
    |--------------------------------------------------------------------------
    |
    | This option defines the default log channel that gets used when writing
    | messages to the logs. The name specified in this option should match
    | one of the channels defined in the "channels" configuration array.
    |
    */

    'default' => env('LOG_CHANNEL', 'stack'),

    // 略

Laravel のディレクトリ直下に保存されている .env を修正します。

LOG_CHANNEL=daily

ターミナルで以下のコマンドを叩いて変更を反映させます(忘れがち)。

$ php artisan config:cache

これで laravel-2019-01-01.log という感じで日別のログファイルが自動的に作られます。

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