Guest User

Untitled

a guest
Nov 19th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Console\Commands;
  4.  
  5. use Symfony\Component\Process\Process;
  6. use Symfony\Component\Process\Exception\ProcessFailedException;
  7. use Illuminate\Console\Command;
  8.  
  9. class LogClearCommand extends Command
  10. {
  11. /**
  12. * The name and signature of the console command.
  13. *
  14. * @var string
  15. */
  16. protected $signature = 'log:clear';
  17.  
  18. /**
  19. * The console command description.
  20. *
  21. * @var string
  22. */
  23. protected $description = 'Clear the log file';
  24.  
  25. /**
  26. * Processs shell
  27. * @var Symfony\Component\Process\Process
  28. */
  29. protected $process;
  30.  
  31. /**
  32. * Create a new command instance.
  33. *
  34. * @return void
  35. */
  36. public function __construct()
  37. {
  38. parent::__construct();
  39. $this->process = new Process('truncate -s 0 storage/logs/laravel.log');
  40. }
  41.  
  42. /**
  43. * Execute the console command.
  44. *
  45. * @return mixed
  46. */
  47. public function handle()
  48. {
  49. $this->process->run();
  50.  
  51. if (!$this->process->isSuccessful()) {
  52. throw new ProcessFailedException($this->process);
  53. }
  54.  
  55. $this->info('Log file cleared!');
  56. }
  57. }
Add Comment
Please, Sign In to add comment