Completed
Push — master ( c86638...b1744c )
by Matze
03:42
created

Log   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 30
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 24 3
1
<?php
2
3
namespace BrainExe\Core\DependencyInjection\CompilerPass;
4
5
use BrainExe\Core\Annotations\CompilerPass;
6
use Monolog\Handler\StreamHandler;
7
use Monolog\Logger;
8
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
9
use Symfony\Component\DependencyInjection\ContainerBuilder;
10
use Symfony\Component\DependencyInjection\Definition;
11
12
/**
13
 * @CompilerPass
14
 */
15
class Log implements CompilerPassInterface
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function process(ContainerBuilder $container)
21
    {
22
        $definition = $container->getDefinition('logger');
23
24
        $logLevels = [
25
            'error.log' => Logger::ERROR,
26
            'info.log' => Logger::INFO,
27
            'info2.log' => Logger::INFO,
28
        ];
29
30
        if ($container->getParameter('debug')) {
31
            $logLevels['debug.log'] = Logger::DEBUG;
32
        }
33
34
        $baseDir = $container->getParameter('logger.dir');
35
        foreach ($logLevels as $file => $level) {
36
            $definition->addMethodCall('pushHandler', [
37
                new Definition(StreamHandler::class, [
38
                    $baseDir . $file,
39
                    $level
40
                ])
41
            ]);
42
        }
43
    }
44
}
45