I was tired today to scroll over the controllers folder to storage folder and vice versa, so I decided to create a command that'll open the latest log file for me in VS Code. Hope it helps:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
class OpenLastLogFile extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'logs:open';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Opens the last log file';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$files = scandir(storage_path('logs'), SCANDIR_SORT_DESCENDING);
$files = array_values(array_filter($files, function ($file) {
return Str::startsWith($file, "laravel-");
}));
if (count($files)) {
$newest_file = $files[0];
exec('code ' . storage_path('logs/'.$newest_file));
} else {
$this->info("There isn't a log file to show! Maybe make some errors first?");
}
}
}