Passed
Push — master ( 8a12fc...8bc538 )
by Vsevolods
10:30
created

Logging   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
lcom 0
cbo 7
dl 0
loc 36
ccs 0
cts 23
cp 0
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 30 2
1
<?php declare(strict_types = 1);
2
3
namespace Venta\Framework\Kernel\Bootstrap;
4
5
use Monolog\Handler\StreamHandler;
6
use Monolog\Logger;
7
use Monolog\Processor\PsrLogMessageProcessor;
8
use Monolog\Processor\WebProcessor;
9
use Psr\Log\LoggerInterface;
10
use Venta\Contracts\Config\Config;
11
use Venta\Framework\Kernel\AbstractKernelBootstrap;
12
13
/**
14
 * Class Logging
15
 *
16
 * @package Venta\Framework\Kernel\Bootstrap
17
 */
18
class Logging extends AbstractKernelBootstrap
19
{
20
    /**
21
     * @inheritDoc
22
     */
23
    public function __invoke()
24
    {
25
        // todo: implement multi-channel configuration.
26
        $this->container->bindFactory(LoggerInterface::class, function (Config $config) {
27
28
            $handler = new StreamHandler(
29
                $this->kernel->getRootPath() . '/storage/logs/venta.log',
30
                $config->log_level ?? Logger::DEBUG
31
            );
32
33
            $handler->pushProcessor(new PsrLogMessageProcessor);
34
35
            if (!$this->kernel->isCli()) {
36
                $handler->pushProcessor(new WebProcessor(null, [ // todo: make list configurable?
37
                    'url' => 'REQUEST_URI',
38
                    'ip' => 'REMOTE_ADDR',
39
                    'http_method' => 'REQUEST_METHOD',
40
                    'server' => 'SERVER_NAME',
41
                    'referrer' => 'HTTP_REFERER',
42
                    'user_agent' => 'HTTP_USER_AGENT',
43
                ]));
44
            }
45
46
            $logger = new Logger('venta');
47
            $logger->pushHandler($handler);
48
49
            return $logger;
50
51
        }, true);
52
    }
53
}
54