简体   繁体   中英

Print/Save complete Laravel Artisan Command output(large array from debug line) to file

I am working in Laravel 6.x project, where I have added debug line inside an Artisan command to get the large array generated from that line into text file as output.

It looks almost like following code in the handle method of said command:

....
if(!$dataArray->isEmpty())
{
    foreach ($dataArr as $dataEle)
    {
        $dataArrToPrnt[] = $dataEle->toArray();
        ....
    }
}
die(var_dump($dataArrToPrnt));
....

But the problem is the dataArray is huge, so after few entries, the command output skips the rest of the data and prints (...more elements) instead.

And I am running the command like below for printing to file(Windows 10 x64 with GitBash, so I have use php.exe instead of php):

php.exe artisan command-namespace:command >> result.out

How can I override/avoid that from happening and print the complete dataArray to file regardless of it's size ?

Try using the global Log. Add a logging channel to your config/logging.php file like so:

'dataLogger' => [
    'driver' => 'daily',
    'path' => storage_path('logs/data.log'),
    'level' => 'info',
],

And use in your code like:

use Log; 
foreach ($dataArr as $dataEle){
    Log::channel('dataLogger')->info($dataEle);
}

(Or however you'd like to format your data.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM