|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BrainExe\Core\DependencyInjection\CompilerPass; |
|
4
|
|
|
|
|
5
|
|
|
use BrainExe\Core\Annotations\CompilerPass; |
|
6
|
|
|
use BrainExe\Core\Logger\ChannelStreamHandler; |
|
7
|
|
|
use Monolog\Handler\ChromePHPHandler; |
|
8
|
|
|
use Monolog\Handler\HipChatHandler; |
|
9
|
|
|
use Monolog\Handler\StreamHandler; |
|
10
|
|
|
use Monolog\Handler\TestHandler; |
|
11
|
|
|
use Monolog\Logger; |
|
12
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
14
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @CompilerPass |
|
19
|
|
|
*/ |
|
20
|
|
|
class LoggerCompilerPass implements CompilerPassInterface |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritdoc} |
|
25
|
|
|
*/ |
|
26
|
4 |
|
public function process(ContainerBuilder $container) |
|
27
|
|
|
{ |
|
28
|
4 |
|
$logger = $container->getDefinition('logger'); |
|
29
|
|
|
|
|
30
|
4 |
|
if ($container->getParameter('debug')) { |
|
31
|
1 |
|
$logger->addMethodCall('pushHandler', [new Definition(ChromePHPHandler::class)]); |
|
32
|
1 |
|
$logger->addMethodCall('pushHandler', [ |
|
33
|
1 |
|
new Definition(StreamHandler::class, ['php://stdout', Logger::INFO]) |
|
34
|
|
|
]); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
4 |
|
if ($container->getParameter('hipchat.api_token')) { |
|
38
|
1 |
|
$logger->addMethodCall('pushHandler', [new Definition(HipChatHandler::class, [ |
|
39
|
1 |
|
$container->getParameter('hipchat.api_token'), |
|
40
|
1 |
|
$container->getParameter('hipchat.room'), |
|
41
|
1 |
|
$container->getParameter('hipchat.name'), |
|
42
|
|
|
false, |
|
43
|
1 |
|
$container->getParameter('hipchat.logLevel'), |
|
44
|
|
|
])]); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
4 |
|
foreach ($container->getParameter('logger.channels') as $config) { |
|
48
|
2 |
|
$logger->addMethodCall('pushHandler', [new Definition(ChannelStreamHandler::class, $config)]); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** @var ParameterBag $parameterBag */ |
|
52
|
4 |
|
$parameterBag = $container->getParameterBag(); |
|
53
|
4 |
|
$parameterBag->remove('logger.channels'); |
|
54
|
4 |
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|