diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/DebugHandlerPass.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/DebugHandlerPass.php new file mode 100644 index 0000000000..f14eb02e5b --- /dev/null +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/DebugHandlerPass.php @@ -0,0 +1,39 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\MonologBundle\DependencyInjection\Compiler; + +use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\Definition; +use Monolog\Logger; + +/** + * Replaces the default logger by another one with its own channel for tagged services. + * + * @author Christophe Coevoet + */ +class DebugHandlerPass implements CompilerPassInterface +{ + protected $channels = array(); + + public function process(ContainerBuilder $container) + { + if (!$container->hasDefinition('monolog.logger_prototype') || !$container->hasDefinition('profiler')) { + return; + } + + $debugHandler = new Definition('%monolog.handler.debug.class%', array(Logger::DEBUG, true)); + $container->setDefinition('monolog.handler.debug', $debugHandler); + $container->getDefinition('monolog.logger_prototype')->addMethodCall('pushHandler', array (new Reference('monolog.handler.debug'))); + } +} diff --git a/src/Symfony/Bundle/MonologBundle/Logger/DebugLogger.php b/src/Symfony/Bundle/MonologBundle/Logger/DebugHandler.php similarity index 91% rename from src/Symfony/Bundle/MonologBundle/Logger/DebugLogger.php rename to src/Symfony/Bundle/MonologBundle/Logger/DebugHandler.php index 94423cfb06..c2c54f5bb8 100644 --- a/src/Symfony/Bundle/MonologBundle/Logger/DebugLogger.php +++ b/src/Symfony/Bundle/MonologBundle/Logger/DebugHandler.php @@ -20,7 +20,7 @@ use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; * * @author Jordi Boggiano */ -class DebugLogger extends TestHandler implements DebugLoggerInterface +class DebugHandler extends TestHandler implements DebugLoggerInterface { /** * {@inheritdoc} diff --git a/src/Symfony/Bundle/MonologBundle/MonologBundle.php b/src/Symfony/Bundle/MonologBundle/MonologBundle.php index 49f25f3aa9..4cacd3cb1d 100644 --- a/src/Symfony/Bundle/MonologBundle/MonologBundle.php +++ b/src/Symfony/Bundle/MonologBundle/MonologBundle.php @@ -14,6 +14,7 @@ namespace Symfony\Bundle\MonologBundle; use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass; +use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\DebugHandlerPass; /** * Bundle. @@ -27,5 +28,6 @@ class MonologBundle extends Bundle parent::build($container); $container->addCompilerPass(new LoggerChannelPass()); + $container->addCompilerPass(new DebugHandlerPass()); } } diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml index 56ca4b4336..645fc16494 100644 --- a/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml @@ -10,6 +10,7 @@ Monolog\Handler\FingersCrossedHandler Monolog\Handler\NullHandler Monolog\Handler\TestHandler + Symfony\Bundle\MonologBundle\Logger\DebugHandler