現象
Laraveのコマンド実行時にログファイルが存在しない状態だと、一部のログが何故か記録されません。
コマンドファイル
php
1<?php 2 3namespace App\Console\Commands; 4 5use Log; 6use Illuminate\Console\Command; 7 8class LogTestCommand extends Command 9{ 10 /** 11 * The name and signature of the console command. 12 * 13 * @var string 14 */ 15 protected $signature = 'test:log'; 16 17 /** 18 * The console command description. 19 * 20 * @var string 21 */ 22 protected $description = 'Command description'; 23 24 /** 25 * Create a new command instance. 26 * 27 * @return void 28 */ 29 public function __construct() 30 { 31 parent::__construct(); 32 } 33 34 /** 35 * Execute the console command. 36 * 37 * @return mixed 38 */ 39 public function handle() 40 { 41 Log::debug('tset 1.'); 42 Log::debug('tset 2.'); 43 Log::debug('tset 3.'); 44 } 45}
コマンド実行
####今日の日付のログファイルがない状態で実行
$ php artisan test:log $ cat storage/logs/laravel-2019-11-28.log [2019-11-28 17:18:32] local.DEBUG: tset 3.
何故か最後だけログされます。
ログファイルがある状態でもう一度実行
$ php artisan test:log $ cat storage/logs/laravel-2019-11-28.log [2019-11-28 17:18:32] local.DEBUG: tset 3. [2019-11-28 17:19:06] local.DEBUG: tset 1. [2019-11-28 17:19:06] local.DEBUG: tset 2. [2019-11-28 17:19:06] local.DEBUG: tset 3.
問題なくログされています。
ログ設定
config/logging.php
php
1 'default' => env('LOG_CHANNEL', 'stack'), 2 3 'channels' => [ 4 'stack' => [ 5 'driver' => 'stack', 6 'channels' => ['daily'], 7 'ignore_exceptions' => false, 8 ], 9 10 'daily' => [ 11 'driver' => 'daily', 12 'path' => storage_path('logs/laravel.log'), 13 'level' => 'debug', 14 'days' => 120, 15 ],
バージョン
Vagrant 2.2.5 ホストOS:Windows 10 ゲストOS:CentOS 7 PHP 7.2.23 (cli) (built: Sep 25 2019 07:56:34) ( NTS ) Laravel Framework 6.5.0
あなたの回答
tips
プレビュー