In PHP's Laravel, how do I clear laravel.log?

Echoing an empty string to it would work, like this :

echo "" > storage/logs/laravel.log

The most efficient would be to truncate it to a size of zero :

truncate -s 0 /app/storage/logs/laravel.log

Here's a reusable artisan command that will save you time and effort :)

Artisan::command('logs:clear', function() {

    exec('rm ' . storage_path('logs/*.log'));

    $this->comment('Logs have been cleared!');

})->describe('Clear log files');

Drop this in routes/console.php then just run php artisan logs:clear


Simply just add this line where you want to clear the log. file_put_contents(storage_path('logs/laravel.log'),'');

Tags:

Php

Laravel 4