Skip to content

Commit 6ea2d32

Browse files
committed
bug #198 Revert "Drop DebugHandlerPass" (stof)
This PR was merged into the 3.x-dev branch. Discussion ---------- Revert "Drop DebugHandlerPass" This reverts commit b46da89. The class is necessary to support Symfony <3.2. Closes #190. The 3.x version of the bundle contains only 2 changes compared to 2.11: - breaking support for Symfony <3.2 (while still announcing compatibility), which is what got reverted here - adding support for a new Monolog feature (which could totally fit in 2.x btw). As we still need to keep support for the Symfony LTS, and the 3.x series is currently broken for us, I'm suggesting here to revert the removal (effectively making it a follow-up of 2.x, which would allow to avoid maintaining 2 branches). The other alternative would be to kill the existing 3.x releases entirely to forbid them to be installed in a Symfony 2.8 project allowing ``symfony/monolog-bundle: ^2.8 || ^3``, but composer does not support yanking existing tags, and git is bad at deleting them (deleting them would require deleting them in all existing clones to be sure that they would never be pushed again to the repo, and then deleting the Packagist versions). Commits ------- 6849b5e Revert "Drop DebugHandlerPass"
2 parents 3c3750b + 6849b5e commit 6ea2d32

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\MonologBundle\DependencyInjection\Compiler;
13+
14+
@trigger_error('The '.__NAMESPACE__.'\DebugHandlerPass class is deprecated since version 2.12 and will be removed in 3.0. Use AddDebugLogProcessorPass in FrameworkBundle instead.', E_USER_DEPRECATED);
15+
16+
use Symfony\Component\DependencyInjection\Reference;
17+
use Symfony\Component\DependencyInjection\ContainerBuilder;
18+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
19+
use Symfony\Component\DependencyInjection\Definition;
20+
use Monolog\Logger;
21+
22+
/**
23+
* Adds the DebugHandler when the profiler is enabled and kernel.debug is true.
24+
*
25+
* @author Christophe Coevoet <stof@notk.org>
26+
* @author Jordi Boggiano <j.boggiano@seld.be>
27+
*
28+
* @deprecated since version 2.12, to be removed in 3.0. Use AddDebugLogProcessorPass in FrameworkBundle instead.
29+
*/
30+
class DebugHandlerPass implements CompilerPassInterface
31+
{
32+
private $channelPass;
33+
34+
public function __construct(LoggerChannelPass $channelPass)
35+
{
36+
$this->channelPass = $channelPass;
37+
}
38+
39+
public function process(ContainerBuilder $container)
40+
{
41+
if (!$container->hasDefinition('profiler')) {
42+
return;
43+
}
44+
45+
if (!$container->getParameter('kernel.debug')) {
46+
return;
47+
}
48+
49+
// disable the DebugHandler in CLI as it tends to leak memory if people enable kernel.debug
50+
if ('cli' === PHP_SAPI) {
51+
return;
52+
}
53+
54+
$debugHandler = new Definition('Symfony\Bridge\Monolog\Handler\DebugHandler', array(Logger::DEBUG, true));
55+
$container->setDefinition('monolog.handler.debug', $debugHandler);
56+
57+
foreach ($this->channelPass->getChannels() as $channel) {
58+
$container
59+
->getDefinition($channel === 'app' ? 'monolog.logger' : 'monolog.logger.'.$channel)
60+
->addMethodCall('pushHandler', array(new Reference('monolog.handler.debug')));
61+
}
62+
}
63+
}

DependencyInjection/Configuration.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@
249249
* - [level]: level name or int value, defaults to DEBUG
250250
* - [bubble]: bool, defaults to true
251251
*
252+
* - debug:
253+
* - [level]: level name or int value, defaults to DEBUG
254+
* - [bubble]: bool, defaults to true
255+
*
252256
* - loggly:
253257
* - token: loggly api token
254258
* - [level]: level name or int value, defaults to DEBUG
@@ -764,6 +768,10 @@ public function getConfigTreeBuilder()
764768
->thenInvalid('The source has to be specified to use a FlowdockHandler')
765769
->end()
766770
->end()
771+
->validate()
772+
->ifTrue(function ($v) { return isset($v['debug']); })
773+
->thenInvalid('The "debug" name cannot be used as it is reserved for the handler of the profiler')
774+
->end()
767775
->example(array(
768776
'syslog' => array(
769777
'type' => 'stream',

DependencyInjection/MonologExtension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
681681
case 'browser_console':
682682
case 'test':
683683
case 'null':
684+
case 'debug':
684685
$definition->setArguments(array(
685686
$handler['level'],
686687
$handler['bubble'],
@@ -736,6 +737,7 @@ private function getHandlerClassByType($handlerType)
736737
'browser_console' => 'Monolog\Handler\BrowserConsoleHandler',
737738
'firephp' => 'Symfony\Bridge\Monolog\Handler\FirePHPHandler',
738739
'chromephp' => 'Symfony\Bridge\Monolog\Handler\ChromePhpHandler',
740+
'debug' => 'Symfony\Bridge\Monolog\Handler\DebugHandler',
739741
'swift_mailer' => 'Symfony\Bridge\Monolog\Handler\SwiftMailerHandler',
740742
'native_mailer' => 'Monolog\Handler\NativeMailerHandler',
741743
'socket' => 'Monolog\Handler\SocketHandler',

MonologBundle.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\HttpKernel\Bundle\Bundle;
1919
use Symfony\Component\DependencyInjection\ContainerBuilder;
2020
use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass;
21+
use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\DebugHandlerPass;
2122
use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\AddProcessorsPass;
2223
use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\FixEmptyLoggerPass;
2324

@@ -33,6 +34,9 @@ public function build(ContainerBuilder $container)
3334
parent::build($container);
3435

3536
$container->addCompilerPass($channelPass = new LoggerChannelPass());
37+
if (!class_exists('Symfony\Bridge\Monolog\Processor\DebugProcessor')) {
38+
$container->addCompilerPass(new DebugHandlerPass($channelPass));
39+
}
3640
$container->addCompilerPass(new FixEmptyLoggerPass($channelPass));
3741
$container->addCompilerPass(new AddProcessorsPass());
3842
$container->addCompilerPass(new AddSwiftMailerTransportPass());

Tests/DependencyInjection/MonologExtensionTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@ public function testExceptionWhenUsingServiceWithoutId()
166166
$loader->load(array(array('handlers' => array('main' => array('type' => 'service')))), $container);
167167
}
168168

169+
/**
170+
* @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
171+
*/
172+
public function testExceptionWhenUsingDebugName()
173+
{
174+
// logger
175+
$container = new ContainerBuilder();
176+
$loader = new MonologExtension();
177+
178+
$loader->load(array(array('handlers' => array('debug' => array('type' => 'stream')))), $container);
179+
}
180+
169181
public function testSyslogHandlerWithLogopts()
170182
{
171183
$container = $this->getContainer(array(array('handlers' => array('main' => array('type' => 'syslog', 'logopts' => LOG_CONS)))));

0 commit comments

Comments
 (0)