Fast way to clear log file directory in Laravel

Fast way to clear log file directory in Laravel

And after my first post of Simple command to open last daily Laravel Log File in VSCode, I have written another command to clear the log files. That helps me reach to the last error easily and start a clean logging session.

Here it is:

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class ClearLogs extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'logs:clear';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Clears the log files';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        exec('rm ' . storage_path('logs/*.log'));
        $this->comment('Logs have been cleared!');
    }
}

Usage:

php artisan logs:clear