RequestsLogger::releaseOutput()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 10
cc 3
nc 2
nop 1
1
<?php
2
3
namespace App\Containers\Debugger\Values;
4
5
use App\Ship\Parents\Values\Value;
6
use Illuminate\Support\Facades\App;
7
use Illuminate\Support\Facades\Config;
8
use Monolog\Formatter\LineFormatter;
9
use Monolog\Handler\StreamHandler;
10
use Monolog\Logger;
11
12
/**
13
 * Class RequestsLogger
14
 *
15
 * @author  Mahmoud Zalt  <[email protected]>
16
 */
17
class RequestsLogger extends Value
18
{
19
20
    CONST TESTING_ENV = 'testing';
21
22
    protected $debuggingEnabled;
23
24
    protected $environment;
25
26
    protected $logger;
27
28
    protected $logFile;
29
30
    /**
31
     * RequestsLogger constructor.
32
     */
33
    public function __construct()
34
    {
35
        $this->prepareConfigs();
36
        $this->prepareLogger();
37
    }
38
39
    /**
40
     * @param \App\Containers\Debugger\Value\Output $output
41
     */
42
    public function releaseOutput(Output $output)
43
    {
44
        if ($this->environment != self::TESTING_ENV && $this->debuggingEnabled === true) {
45
            $this->logger->info($output->get());
46
        }
47
    }
48
49
    /**
50
     * @void
51
     */
52
    private function prepareConfigs()
53
    {
54
        $this->environment = App::environment();
0 ignored issues
show
Bug introduced by Mahmoud Zalt
The call to environment() misses a required argument $...$environments.

This check looks for function calls that miss required arguments.

Loading history...
55
        $this->debuggingEnabled = Config::get("debugger.requests.debug");
56
        $this->logFile = Config::get("debugger.requests.log_file");
57
    }
58
59
    /**
60
     * @void
61
     */
62
    private function prepareLogger()
63
    {
64
        $handler = new StreamHandler(storage_path('logs/' . $this->logFile));
65
        $handler->setFormatter(new LineFormatter(null, null, true, true));
66
67
        $this->logger = new Logger("REQUESTS DEBUGGER");
68
        $this->logger->pushHandler($handler);
69
    }
70
}
71