4_1_Laravel Logの設定 - hpscript/laravel GitHub Wiki

.env

Log channelはdefaultでstackに設定されている

LOG_CHANNEL=stack

config/logging.php

stackで、channelsは'single'に設定されています。

'channels' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => ['single'],
            'ignore_exceptions' => false,
        ],

        'single' => [
            'driver' => 'single',
            'path' => storage_path('logs/laravel.log'),
            'level' => 'debug',
        ],
        // 省略
    ],

ログの出力先

storate/logs/laravel.log

###コマンドラインで出力 less +F storage/logs/laravel.log

controllerからログ出力

$ php artisan make:controller --resource LogController

Route::get('log', 'LogController@index');
public function index()
    {
        //
        \Log::info('ログ出力test');
        return 'test';
    }

heplerを使う場合

logger()->info('something has happened');

laravel.log

[2020-02-24 14:13:10] local.INFO: ログ出力test 
[2020-02-24 14:22:10] local.INFO: something has happened  

ログレベル

emergency, alert, critical, error, warning, notice, info, debug