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

Log::process()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 3
eloc 14
nc 4
nop 1
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