Created
November 11, 2019 01:50
-
-
Save ifaniqbal/2d9c41583ee2032eb0052bac4fe405e8 to your computer and use it in GitHub Desktop.
Laravel Artisan Command To Simplify Log Files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Console\Commands; | |
use Illuminate\Console\Command; | |
class SimplifyLog extends Command | |
{ | |
/** | |
* The name and signature of the console command. | |
* | |
* @var string | |
*/ | |
protected $signature = 'simplify {logname}'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Simplify Log'; | |
/** | |
* Create a new command instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
parent::__construct(); | |
} | |
/** | |
* Execute the console command. | |
* | |
* @return mixed | |
*/ | |
public function handle() | |
{ | |
$logname = $this->argument('logname'); | |
$input_path = storage_path('logs/' . $logname); | |
$output_path = storage_path('app/' . $logname); | |
$input = fopen($input_path, "r"); | |
$output = fopen($output_path, 'w'); | |
while (!feof($input)) { | |
$line = fgets($input); | |
if ($line[0] == '[' && $line[1] != 's') { | |
fwrite($output, substr($line, 22)); | |
} | |
} | |
fclose($input); | |
fclose($output); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment