Completed
Push — master ( 0bd2ec...b69e83 )
by Vladimir
02:54
created

Log::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Toolbelt\Commands;
6
7
use FondBot\Toolbelt\Command;
8
use Symfony\Component\Process\Process;
9
10
class Log extends Command
11
{
12
    protected function configure()
13
    {
14
        $this
15
            ->setName('log')
16
            ->setDescription('Tail log.');
17
    }
18
19
    /**
20
     * Handle command.
21
     *
22
     * @throws \Symfony\Component\Process\Exception\InvalidArgumentException
23
     * @throws \Symfony\Component\Process\Exception\LogicException
24
     * @throws \Symfony\Component\Process\Exception\RuntimeException
25
     * @throws \Psr\Container\ContainerExceptionInterface
26
     */
27
    public function handle(): void
28
    {
29
        $path = $this->kernel->resolve('application_log');
30
        $command = 'tail -f -n 1000 '.escapeshellarg($path);
31
32
        (new Process($command))->setTimeout(null)->run(function ($type, $line) {
33
            $this->line($line);
34
        });
35
    }
36
}
37