From 0f41fbe0a69af0f74471c0dc24ae02a7201988e7 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 24 Feb 2011 22:05:08 +0100 Subject: [PATCH 01/16] [MonologBundle] Added the MonologBundle --- .../DependencyInjection/Configuration.php | 64 +++++++++ .../DependencyInjection/MonologExtension.php | 125 ++++++++++++++++++ .../MonologBundle/Logger/DebugLogger.php | 40 ++++++ .../Bundle/MonologBundle/Logger/Logger.php | 47 +++++++ .../Bundle/MonologBundle/MonologBundle.php | 23 ++++ .../Resources/config/monolog.xml | 18 +++ .../Resources/config/schema/monolog-1.0.xsd | 34 +++++ .../Bundle/MonologBundle/Tests/TestCase.php | 22 +++ 8 files changed, 373 insertions(+) create mode 100644 src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php create mode 100644 src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php create mode 100644 src/Symfony/Bundle/MonologBundle/Logger/DebugLogger.php create mode 100644 src/Symfony/Bundle/MonologBundle/Logger/Logger.php create mode 100644 src/Symfony/Bundle/MonologBundle/MonologBundle.php create mode 100644 src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml create mode 100644 src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd create mode 100644 src/Symfony/Bundle/MonologBundle/Tests/TestCase.php diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php new file mode 100644 index 0000000000000..38dad0f89780e --- /dev/null +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -0,0 +1,64 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\MonologBundle\DependencyInjection; + +use Symfony\Component\Config\Definition\Builder\NodeBuilder; +use Symfony\Component\Config\Definition\Builder\TreeBuilder; + +/** + * This class contains the configuration information for the bundle + * + * This information is solely responsible for how the different configuration + * sections are normalized, and merged. + * + * @author Jordi Boggiano + */ +class Configuration +{ + /** + * Generates the configuration tree. + * + * @return \Symfony\Component\Config\Definition\NodeInterface + */ + public function getConfigTree() + { + $treeBuilder = new TreeBuilder(); + $rootNode = $treeBuilder->root('monolog', 'array'); + + // TODO update XSD to match this + $rootNode + ->arrayNode('handlers') + ->fixXmlConfig('handler') + ->canBeUnset() + ->performNoDeepMerging() + ->prototype('array') + ->performNoDeepMerging() + // TODO lowercase the type always + ->scalarNode('type')->isRequired()->end() + ->scalarNode('action_level')->end() + ->scalarNode('level')->defaultValue('INFO')->end() + ->scalarNode('path')->end() + ->scalarNode('bubble')->end() + ->scalarNode('buffer_size')->end() + ->arrayNode('handler') + ->performNoDeepMerging() + ->scalarNode('type')->isRequired()->end() + ->scalarNode('level')->defaultValue('DEBUG')->end() + ->scalarNode('path')->end() + ->end() + ->end() + ->end() + ; + + return $treeBuilder->buildTree(); + } +} diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php new file mode 100644 index 0000000000000..ac06e621e8a69 --- /dev/null +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php @@ -0,0 +1,125 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\MonologBundle\DependencyInjection; + +use Symfony\Component\HttpKernel\DependencyInjection\Extension; +use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\Config\FileLocator; +use Symfony\Component\Config\Definition\Processor; +use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\DependencyInjection\Parameter; + +/** + * MonologExtension is an extension for the Monolog library. + * + * @author Jordi Boggiano + */ +class MonologExtension extends Extension +{ + /** + * Loads the Monolog configuration. + * + * Usage example: + * + * monolog: + * handlers: + * myhandler: + * level: info + * path: path/to/some.log + * + * @param array $config An array of configuration settings + * @param ContainerBuilder $container A ContainerBuilder instance + */ + public function load(array $configs, ContainerBuilder $container) + { + $configuration = new Configuration(); + $processor = new Processor(); + $config = $processor->process($configuration->getConfigTree(), $configs); + + if (isset($config['handlers'])) { + $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader->load('monolog.xml'); + $container->setAlias('logger', 'monolog.logger'); + + $logger = $container->getDefinition('monolog.logger'); + + $handlers = array(); + foreach ($config['handlers'] as $handler) { + $handlers[] = $this->buildHandler($container, $handler); + } + + // TODO somehow the DebugLogger should be pushed on the stack as well, or that concept needs to be changed + // didn't have to investigate yet what it is exactly + $handlers = array_reverse($handlers); + foreach ($handlers as $handler) { + $logger->addMethodCall('pushHandler', array($handler)); + } + } + } + + public function buildHandler(ContainerBuilder $container, array $handler) + { + $definition = new Definition(new Parameter('monolog.handler.'.$handler['type'].'.class')); + $handler['level'] = is_int($handler['level']) ? $handler['level'] : constant('Monolog\Logger::'.strtoupper($handler['level'])); + + switch ($handler['type']) { + case 'stream': + if (!isset($handler['path'])) { + $handler['path'] = '%kernel.logs_dir%/%kernel.environment%.log'; + } + + $definition->setArguments(array( + $handler['path'], + $handler['level'], + isset($handler['bubble']) ? $handler['bubble'] : false, + )); + break; + + case 'fingerscrossed': + if (!isset($handler['handler'])) { + // TODO validate that in Config class? + throw new \InvalidArgumentException('Handler sub-node is missing.'); + } + if (!isset($handler['action_level'])) { + $handler['action_level'] = 'WARNING'; + } + $handler['action_level'] = is_int($handler['action_level']) ? $handler['action_level'] : constant('Monolog\Logger::'.strtoupper($handler['action_level'])); + + $definition->setArguments(array( + $this->buildHandler($container, $handler['handler']), + $handler['action_level'], + isset($handler['buffer_size']) ? $handler['buffer_size'] : 0, + isset($handler['bubble']) ? $handler['bubble'] : false, + )); + break; + } + + return $definition; + } + + /** + * Returns the base path for the XSD files. + * + * @return string The XSD base path + */ + public function getXsdValidationBasePath() + { + return __DIR__.'/../Resources/config/schema'; + } + + public function getNamespace() + { + return 'http://www.symfony-project.org/schema/dic/monolog'; + } +} diff --git a/src/Symfony/Bundle/MonologBundle/Logger/DebugLogger.php b/src/Symfony/Bundle/MonologBundle/Logger/DebugLogger.php new file mode 100644 index 0000000000000..94423cfb06fb9 --- /dev/null +++ b/src/Symfony/Bundle/MonologBundle/Logger/DebugLogger.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\MonologBundle\Logger; + +use Monolog\Handler\TestHandler; +use Monolog\Logger; +use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; + +/** + * DebugLogger. + * + * @author Jordi Boggiano + */ +class DebugLogger extends TestHandler implements DebugLoggerInterface +{ + /** + * {@inheritdoc} + */ + public function getLogs() + { + return $this->messages; + } + + /** + * {@inheritdoc} + */ + public function countErrors() + { + return count($this->messagesByLevel[Logger::ERROR]); + } +} diff --git a/src/Symfony/Bundle/MonologBundle/Logger/Logger.php b/src/Symfony/Bundle/MonologBundle/Logger/Logger.php new file mode 100644 index 0000000000000..cea71143c67e4 --- /dev/null +++ b/src/Symfony/Bundle/MonologBundle/Logger/Logger.php @@ -0,0 +1,47 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\MonologBundle\Logger; + +use Monolog\Logger as BaseLogger; +use Symfony\Component\HttpKernel\Log\LoggerInterface; +use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; + +/** + * Logger. + * + * @author Fabien Potencier + */ +class Logger extends BaseLogger implements LoggerInterface +{ + /** + * Returns a DebugLoggerInterface instance if one is registered with this logger. + * + * @return DebugLoggerInterface A DebugLoggerInterface instance or null if none is registered + */ + public function getDebugLogger() + { + $handler = $this->handler; + while ($handler) { + if ($handler instanceof DebugLoggerInterface) { + return $handler; + } + $handler = $handler->getParent(); + } + + return null; + } + + public function log($message, $level) + { + return $this->addMessage($level, $message); + } +} diff --git a/src/Symfony/Bundle/MonologBundle/MonologBundle.php b/src/Symfony/Bundle/MonologBundle/MonologBundle.php new file mode 100644 index 0000000000000..8d40599886450 --- /dev/null +++ b/src/Symfony/Bundle/MonologBundle/MonologBundle.php @@ -0,0 +1,23 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\MonologBundle; + +use Symfony\Component\HttpKernel\Bundle\Bundle; + +/** + * Bundle. + * + * @author Jordi Boggiano + */ +class MonologBundle extends Bundle +{ +} diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml new file mode 100644 index 0000000000000..51f3320d5671b --- /dev/null +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml @@ -0,0 +1,18 @@ + + + + + + Symfony\Bundle\MonologBundle\Logger\Logger + Monolog\Handler\StreamHandler + Monolog\Handler\FingersCrossedHandler + + + + + framework + + + diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd new file mode 100644 index 0000000000000..711f703b8188b --- /dev/null +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Symfony/Bundle/MonologBundle/Tests/TestCase.php b/src/Symfony/Bundle/MonologBundle/Tests/TestCase.php new file mode 100644 index 0000000000000..4d31cb712f783 --- /dev/null +++ b/src/Symfony/Bundle/MonologBundle/Tests/TestCase.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\MonologBundle\Tests; + +class TestCase extends \PHPUnit_Framework_TestCase +{ + protected function setUp() + { + if (!class_exists('Monolog\Logger')) { + $this->markTestSkipped('Monolog is not available.'); + } + } +} From c495d3cc0eb7826abd2b0b3ca0d168d581270e62 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 24 Feb 2011 22:06:12 +0100 Subject: [PATCH 02/16] Added monolog to autoload and vendors script --- autoload.php.dist | 1 + vendors.sh | 3 +++ 2 files changed, 4 insertions(+) diff --git a/autoload.php.dist b/autoload.php.dist index fea397bb8ad16..6abb60cf2e783 100644 --- a/autoload.php.dist +++ b/autoload.php.dist @@ -16,6 +16,7 @@ $loader->registerNamespaces(array( 'Doctrine' => __DIR__.'/vendor/doctrine/lib', 'Zend' => __DIR__.'/vendor/zend/library', 'Assetic' => __DIR__.'/vendor/assetic/src', + 'Monolog' => __DIR__.'/vendor/monolog/src', )); $loader->registerPrefixes(array( 'Swift_' => __DIR__.'/vendor/swiftmailer/lib/classes', diff --git a/vendors.sh b/vendors.sh index 7080580524a06..f948d78767c34 100755 --- a/vendors.sh +++ b/vendors.sh @@ -58,6 +58,9 @@ install_git doctrine-mongodb git://github.com/doctrine/mongodb.git # Doctrine MongoDB install_git doctrine-mongodb-odm git://github.com/doctrine/mongodb-odm.git +# Monolog +install_git monolog git://github.com/Seldaek/monolog.git + # Swiftmailer install_git swiftmailer git://github.com/swiftmailer/swiftmailer.git origin/4.1 From 2e207a2f405ec9919d9b820724d0515750edd148 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Thu, 24 Feb 2011 23:59:59 +0100 Subject: [PATCH 03/16] Fixed Configuration class, updated XSD schema and resolved some TODOs --- .../DependencyInjection/Configuration.php | 27 ++++++++++++++----- .../DependencyInjection/MonologExtension.php | 8 ++---- .../Resources/config/schema/monolog-1.0.xsd | 26 ++++++++++++++---- 3 files changed, 44 insertions(+), 17 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php index 38dad0f89780e..cc84f6aa059d3 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -34,27 +34,42 @@ public function getConfigTree() $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('monolog', 'array'); - // TODO update XSD to match this $rootNode + ->fixXmlConfig('handler') ->arrayNode('handlers') - ->fixXmlConfig('handler') ->canBeUnset() ->performNoDeepMerging() + ->useAttributeAsKey('name') ->prototype('array') ->performNoDeepMerging() - // TODO lowercase the type always - ->scalarNode('type')->isRequired()->end() + ->scalarNode('type') + ->isRequired() + ->beforeNormalization() + ->always() + ->then(function($v) { return strtolower($v); }) + ->end() + ->end() ->scalarNode('action_level')->end() ->scalarNode('level')->defaultValue('INFO')->end() ->scalarNode('path')->end() - ->scalarNode('bubble')->end() + ->booleanNode('bubble')->defaultFalse()->end() ->scalarNode('buffer_size')->end() ->arrayNode('handler') ->performNoDeepMerging() - ->scalarNode('type')->isRequired()->end() + ->scalarNode('type') + ->isRequired() + ->beforeNormalization() + ->always() + ->then(function($v) { return strtolower($v); }) + ->end() + ->end() ->scalarNode('level')->defaultValue('DEBUG')->end() ->scalarNode('path')->end() ->end() + ->validate() + ->ifTrue(function($v) { return 'fingerscrossed' === $v['type'] && !isset($v['handler']); }) + ->thenInvalid('The handler has to be specified to use a FingersCrossedHandler') + ->end() ->end() ->end() ; diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php index ac06e621e8a69..8a56c18de7c90 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php @@ -82,15 +82,11 @@ public function buildHandler(ContainerBuilder $container, array $handler) $definition->setArguments(array( $handler['path'], $handler['level'], - isset($handler['bubble']) ? $handler['bubble'] : false, + $handler['bubble'], )); break; case 'fingerscrossed': - if (!isset($handler['handler'])) { - // TODO validate that in Config class? - throw new \InvalidArgumentException('Handler sub-node is missing.'); - } if (!isset($handler['action_level'])) { $handler['action_level'] = 'WARNING'; } @@ -100,7 +96,7 @@ public function buildHandler(ContainerBuilder $container, array $handler) $this->buildHandler($container, $handler['handler']), $handler['action_level'], isset($handler['buffer_size']) ? $handler['buffer_size'] : 0, - isset($handler['bubble']) ? $handler['bubble'] : false, + $handler['bubble'], )); break; } diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd index 711f703b8188b..9605347709779 100644 --- a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd @@ -8,14 +8,24 @@ - - - + + + - - + + + + + + + + + + + + @@ -31,4 +41,10 @@ + + + + + + From 786df627ac831d58c1b4c0352c744a8d03ee25e1 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 25 Feb 2011 10:09:22 +0100 Subject: [PATCH 04/16] [MonologBundle] Some code reorganisation --- .../MonologBundle/DependencyInjection/Configuration.php | 9 +++++---- .../Resources/config/schema/monolog-1.0.xsd | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php index cc84f6aa059d3..a3f61aa104447 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -49,11 +49,11 @@ public function getConfigTree() ->then(function($v) { return strtolower($v); }) ->end() ->end() - ->scalarNode('action_level')->end() ->scalarNode('level')->defaultValue('INFO')->end() - ->scalarNode('path')->end() ->booleanNode('bubble')->defaultFalse()->end() - ->scalarNode('buffer_size')->end() + ->scalarNode('path')->end() // stream specific + ->scalarNode('action_level')->end() // fingerscrossed specific + ->scalarNode('buffer_size')->end() // fingerscrossed specific ->arrayNode('handler') ->performNoDeepMerging() ->scalarNode('type') @@ -64,7 +64,8 @@ public function getConfigTree() ->end() ->end() ->scalarNode('level')->defaultValue('DEBUG')->end() - ->scalarNode('path')->end() + ->booleanNode('bubble')->defaultFalse()->end() + ->scalarNode('path')->end() // stream specific ->end() ->validate() ->ifTrue(function($v) { return 'fingerscrossed' === $v['type'] && !isset($v['handler']); }) diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd index 9605347709779..22b646be95af5 100644 --- a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd @@ -23,7 +23,6 @@ - @@ -45,6 +44,7 @@ + From 937aa1c1878b55ccbff0bae413fc2bbeef62556b Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 25 Feb 2011 10:09:42 +0100 Subject: [PATCH 05/16] [MonologBundle] Added path validation --- .../Bundle/MonologBundle/DependencyInjection/Configuration.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php index a3f61aa104447..e714da14caf5e 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -70,6 +70,8 @@ public function getConfigTree() ->validate() ->ifTrue(function($v) { return 'fingerscrossed' === $v['type'] && !isset($v['handler']); }) ->thenInvalid('The handler has to be specified to use a FingersCrossedHandler') + ->ifTrue(function($v) { return 'stream' === $v['type'] && !isset($v['path']); }) + ->thenInvalid('The path has to be specified to use a StreamHandler') ->end() ->end() ->end() From ec8880a563ac982d8269c858778c14ae938dbbcc Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Fri, 25 Feb 2011 11:24:52 +0100 Subject: [PATCH 06/16] Fixed previous commit --- .../MonologBundle/DependencyInjection/Configuration.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php index e714da14caf5e..6817324063bc7 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -66,10 +66,16 @@ public function getConfigTree() ->scalarNode('level')->defaultValue('DEBUG')->end() ->booleanNode('bubble')->defaultFalse()->end() ->scalarNode('path')->end() // stream specific + ->validate() + ->ifTrue(function($v) { return 'stream' === $v['type'] && !isset($v['path']); }) + ->thenInvalid('The path has to be specified to use a StreamHandler') + ->end() ->end() ->validate() ->ifTrue(function($v) { return 'fingerscrossed' === $v['type'] && !isset($v['handler']); }) ->thenInvalid('The handler has to be specified to use a FingersCrossedHandler') + ->end() + ->validate() ->ifTrue(function($v) { return 'stream' === $v['type'] && !isset($v['path']); }) ->thenInvalid('The path has to be specified to use a StreamHandler') ->end() From bd0f0052d61005de8f2a0449ee60a237b6490686 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Fri, 25 Feb 2011 11:35:21 +0100 Subject: [PATCH 07/16] Refactored the configuration class to be DRY --- .../DependencyInjection/Configuration.php | 65 +++++++++---------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php index 6817324063bc7..223f882258974 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -34,55 +34,52 @@ public function getConfigTree() $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('monolog', 'array'); - $rootNode + $handlersPrototype = $rootNode ->fixXmlConfig('handler') ->arrayNode('handlers') ->canBeUnset() ->performNoDeepMerging() ->useAttributeAsKey('name') ->prototype('array') - ->performNoDeepMerging() - ->scalarNode('type') - ->isRequired() - ->beforeNormalization() - ->always() - ->then(function($v) { return strtolower($v); }) - ->end() - ->end() - ->scalarNode('level')->defaultValue('INFO')->end() - ->booleanNode('bubble')->defaultFalse()->end() - ->scalarNode('path')->end() // stream specific ->scalarNode('action_level')->end() // fingerscrossed specific ->scalarNode('buffer_size')->end() // fingerscrossed specific - ->arrayNode('handler') - ->performNoDeepMerging() - ->scalarNode('type') - ->isRequired() - ->beforeNormalization() - ->always() - ->then(function($v) { return strtolower($v); }) - ->end() - ->end() - ->scalarNode('level')->defaultValue('DEBUG')->end() - ->booleanNode('bubble')->defaultFalse()->end() - ->scalarNode('path')->end() // stream specific - ->validate() - ->ifTrue(function($v) { return 'stream' === $v['type'] && !isset($v['path']); }) - ->thenInvalid('The path has to be specified to use a StreamHandler') - ->end() - ->end() + ->builder($this->getHandlerSubnode()) ->validate() ->ifTrue(function($v) { return 'fingerscrossed' === $v['type'] && !isset($v['handler']); }) ->thenInvalid('The handler has to be specified to use a FingersCrossedHandler') ->end() - ->validate() - ->ifTrue(function($v) { return 'stream' === $v['type'] && !isset($v['path']); }) - ->thenInvalid('The path has to be specified to use a StreamHandler') - ->end() + ; + $this->addHandlerSection($handlersPrototype); + + return $treeBuilder->buildTree(); + } + + private function addHandlerSection(NodeBuilder $node) + { + $node + ->performNoDeepMerging() + ->scalarNode('type') + ->isRequired() + ->beforeNormalization() + ->always() + ->then(function($v) { return strtolower($v); }) ->end() ->end() + ->scalarNode('level')->defaultValue('DEBUG')->end() + ->booleanNode('bubble')->defaultFalse()->end() + ->scalarNode('path')->end() // stream specific + ->validate() + ->ifTrue(function($v) { return 'stream' === $v['type'] && !isset($v['path']); }) + ->thenInvalid('The path has to be specified to use a StreamHandler') + ->end() ; + } - return $treeBuilder->buildTree(); + private function getHandlerSubnode() + { + $node = new NodeBuilder('handler', 'array'); + $this->addHandlerSection($node); + + return $node; } } From 21a4cc930f412613aa2ae1eb556bdf01b3fbb84c Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Fri, 25 Feb 2011 11:44:30 +0100 Subject: [PATCH 08/16] Added support of NullHandler and TestHandler --- .../MonologBundle/DependencyInjection/Configuration.php | 1 + .../MonologBundle/DependencyInjection/MonologExtension.php | 7 +++++++ .../Bundle/MonologBundle/Resources/config/monolog.xml | 2 ++ 3 files changed, 10 insertions(+) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php index 223f882258974..5b64bc27095cd 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -60,6 +60,7 @@ private function addHandlerSection(NodeBuilder $node) ->performNoDeepMerging() ->scalarNode('type') ->isRequired() + ->treatNullLike('null') ->beforeNormalization() ->always() ->then(function($v) { return strtolower($v); }) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php index 8a56c18de7c90..86e0bba10e72f 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php @@ -99,6 +99,13 @@ public function buildHandler(ContainerBuilder $container, array $handler) $handler['bubble'], )); break; + default: + // Handler using the constructor of AbstractHandler without adding their own arguments + $definition->setArguments(array( + $handler['level'], + $handler['bubble'], + )); + break; } return $definition; diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml index 51f3320d5671b..f158594f41143 100644 --- a/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml @@ -8,6 +8,8 @@ Symfony\Bundle\MonologBundle\Logger\Logger Monolog\Handler\StreamHandler Monolog\Handler\FingersCrossedHandler + Monolog\Handler\NullHandler + Monolog\Handler\TestHandler From dbed0eaa20ec6590a461b66306e2f001afc01dd3 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Fri, 25 Feb 2011 11:45:24 +0100 Subject: [PATCH 09/16] Removed the path validation as the default value is set by the extension --- .../MonologBundle/DependencyInjection/Configuration.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php index 5b64bc27095cd..128f2a167bc31 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -69,10 +69,6 @@ private function addHandlerSection(NodeBuilder $node) ->scalarNode('level')->defaultValue('DEBUG')->end() ->booleanNode('bubble')->defaultFalse()->end() ->scalarNode('path')->end() // stream specific - ->validate() - ->ifTrue(function($v) { return 'stream' === $v['type'] && !isset($v['path']); }) - ->thenInvalid('The path has to be specified to use a StreamHandler') - ->end() ; } From d0db085c6c1fb5fe41709fd8f6839d7d1da59025 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Fri, 25 Feb 2011 17:43:50 +0100 Subject: [PATCH 10/16] Added support for different channels through tags All channels will use the same handlers but a different channel name. This allows to easily know which part of the application generated this message. --- .../Compiler/LoggerChannelPass.php | 59 +++++++++++++++++++ .../DependencyInjection/MonologExtension.php | 16 ++--- .../Bundle/MonologBundle/MonologBundle.php | 8 +++ .../Resources/config/monolog.xml | 7 ++- .../Compiler/LoggerChannelPassTest.php | 54 +++++++++++++++++ 5 files changed, 135 insertions(+), 9 deletions(-) create mode 100644 src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/LoggerChannelPass.php create mode 100644 src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/Compiler/LoggerChannelPassTest.php diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/LoggerChannelPass.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/LoggerChannelPass.php new file mode 100644 index 0000000000000..c0bb7cd4ccae2 --- /dev/null +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/LoggerChannelPass.php @@ -0,0 +1,59 @@ + + * + * 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\DefinitionDecorator; + +/** + * Replaces the default logger by another one with its own channel for tagged services. + * + * @author Christophe Coevoet + */ +class LoggerChannelPass implements CompilerPassInterface +{ + protected $channels = array(); + + public function process(ContainerBuilder $container) + { + if (false === $container->hasDefinition('monolog.logger')) { + return; + } + + foreach ($container->findTaggedServiceIds('monolog.logger') as $id => $tags) { + foreach ($tags as $tag) { + if (!empty ($tag['channel']) && 'app' !== $tag['channel']) { + $definition = $container->getDefinition($id); + $loggerId = sprintf('monolog.logger.%s', $tag['channel']); + $this->createLogger($tag['channel'], $loggerId, $container); + foreach ($definition->getArguments() as $index => $argument) { + if ($argument instanceof Reference && 'logger' === (string) $argument) { + $definition->setArgument($index, new Reference($loggerId, $argument->getInvalidBehavior(), $argument->isStrict())); + } + } + } + } + } + } + + protected function createLogger($channel, $loggerId, ContainerBuilder $container) + { + if (!in_array($channel, $this->channels)) { + $logger = new DefinitionDecorator('monolog.logger_prototype'); + $logger->setArgument(0, $channel); + $container->setDefinition($loggerId, $logger); + array_push($this->channels, $channel); + } + } +} diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php index 86e0bba10e72f..4c8b6d1dcaef1 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php @@ -52,25 +52,26 @@ public function load(array $configs, ContainerBuilder $container) $loader->load('monolog.xml'); $container->setAlias('logger', 'monolog.logger'); - $logger = $container->getDefinition('monolog.logger'); + $logger = $container->getDefinition('monolog.logger.prototype'); $handlers = array(); - foreach ($config['handlers'] as $handler) { - $handlers[] = $this->buildHandler($container, $handler); + foreach ($config['handlers'] as $name => $handler) { + $handlers[] = $this->buildHandler($container, $name, $handler); } // TODO somehow the DebugLogger should be pushed on the stack as well, or that concept needs to be changed // didn't have to investigate yet what it is exactly $handlers = array_reverse($handlers); foreach ($handlers as $handler) { - $logger->addMethodCall('pushHandler', array($handler)); + $logger->addMethodCall('pushHandler', array(new Reference($handler))); } } } - public function buildHandler(ContainerBuilder $container, array $handler) + public function buildHandler(ContainerBuilder $container, $name, array $handler) { - $definition = new Definition(new Parameter('monolog.handler.'.$handler['type'].'.class')); + $handlerId = sprintf('monolog.handler.%s', $name); + $definition = new Definition(sprintf('%monolog.handler.%s.class%', $handler['type'])); $handler['level'] = is_int($handler['level']) ? $handler['level'] : constant('Monolog\Logger::'.strtoupper($handler['level'])); switch ($handler['type']) { @@ -107,8 +108,9 @@ public function buildHandler(ContainerBuilder $container, array $handler) )); break; } + $container->setDefinition($handlerId, $definition); - return $definition; + return $handlerId; } /** diff --git a/src/Symfony/Bundle/MonologBundle/MonologBundle.php b/src/Symfony/Bundle/MonologBundle/MonologBundle.php index 8d40599886450..49f25f3aa98d8 100644 --- a/src/Symfony/Bundle/MonologBundle/MonologBundle.php +++ b/src/Symfony/Bundle/MonologBundle/MonologBundle.php @@ -12,6 +12,8 @@ namespace Symfony\Bundle\MonologBundle; use Symfony\Component\HttpKernel\Bundle\Bundle; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass; /** * Bundle. @@ -20,4 +22,10 @@ */ class MonologBundle extends Bundle { + public function build(ContainerBuilder $container) + { + parent::build($container); + + $container->addCompilerPass(new LoggerChannelPass()); + } } diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml index f158594f41143..56ca4b4336b11 100644 --- a/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml @@ -13,8 +13,11 @@ - - framework + + app + + + diff --git a/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/Compiler/LoggerChannelPassTest.php b/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/Compiler/LoggerChannelPassTest.php new file mode 100644 index 0000000000000..7e2b9558fe11a --- /dev/null +++ b/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/Compiler/LoggerChannelPassTest.php @@ -0,0 +1,54 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Compiler; + +use Symfony\Bundle\MonologBundle\Tests\TestCase; +use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass; +use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; + +class LoggerChannelPassTest extends TestCase +{ + public function testProcess() + { + $container = $this->getContainer(); + $this->assertTrue($container->hasDefinition('monolog.logger.test'), '->process adds a logger service for tagged service'); + + $service = $container->getDefinition('test'); + $arguments = $service->getArguments(); + $this->assertEquals('monolog.logger.test', (string) $arguments[1], '->process replaces the logger by the new one'); + } + + protected function getContainer() + { + $container = new ContainerBuilder(); + $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config')); + $loader->load('monolog.xml'); + $definition = $container->getDefinition('monolog.logger_prototype'); + $container->set('monolog.handler.test', new Definition('%monolog.handler.null.class%', array (100, false))); + $definition->addMethodCall('pushHandler', array(new Reference('monolog.handler.test'))); + + $service = new Definition('TestClass', array('false', new Reference('logger'))); + $service->addTag('monolog.logger', array ('channel' => 'test')); + $container->setDefinition('test', $service); + + $container->getCompilerPassConfig()->setOptimizationPasses(array()); + $container->getCompilerPassConfig()->setRemovingPasses(array()); + $container->addCompilerPass(new LoggerChannelPass()); + $container->compile(); + + return $container; + } +} From 4e7117efff5f7fa6b3d1cd56ddacaa86f908b952 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 25 Feb 2011 22:19:54 +0100 Subject: [PATCH 11/16] Fixed typos in previous commits --- .../MonologBundle/DependencyInjection/MonologExtension.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php index 4c8b6d1dcaef1..c66e783684bf1 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php @@ -52,7 +52,7 @@ public function load(array $configs, ContainerBuilder $container) $loader->load('monolog.xml'); $container->setAlias('logger', 'monolog.logger'); - $logger = $container->getDefinition('monolog.logger.prototype'); + $logger = $container->getDefinition('monolog.logger_prototype'); $handlers = array(); foreach ($config['handlers'] as $name => $handler) { @@ -71,7 +71,7 @@ public function load(array $configs, ContainerBuilder $container) public function buildHandler(ContainerBuilder $container, $name, array $handler) { $handlerId = sprintf('monolog.handler.%s', $name); - $definition = new Definition(sprintf('%monolog.handler.%s.class%', $handler['type'])); + $definition = new Definition(sprintf('%%monolog.handler.%s.class%%', $handler['type'])); $handler['level'] = is_int($handler['level']) ? $handler['level'] : constant('Monolog\Logger::'.strtoupper($handler['level'])); switch ($handler['type']) { From c36da08eee439f1d7465041c2cb40eddf4e590a6 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 25 Feb 2011 22:20:16 +0100 Subject: [PATCH 12/16] Updated Logger class to match latest Monolog updates --- src/Symfony/Bundle/MonologBundle/Logger/Logger.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/Logger/Logger.php b/src/Symfony/Bundle/MonologBundle/Logger/Logger.php index cea71143c67e4..e8a534837bfa2 100644 --- a/src/Symfony/Bundle/MonologBundle/Logger/Logger.php +++ b/src/Symfony/Bundle/MonologBundle/Logger/Logger.php @@ -29,15 +29,11 @@ class Logger extends BaseLogger implements LoggerInterface */ public function getDebugLogger() { - $handler = $this->handler; - while ($handler) { + foreach ($this->handlers as $handler) { if ($handler instanceof DebugLoggerInterface) { return $handler; } - $handler = $handler->getParent(); } - - return null; } public function log($message, $level) From 95c6fe20e33089f4d2ca2b3cad812b222b5299b6 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 25 Feb 2011 23:09:45 +0100 Subject: [PATCH 13/16] Added monolog tags to create all core channels --- .../DoctrineBundle/Resources/config/dbal.xml | 1 + .../Resources/config/mongodb.xml | 3 +- .../Resources/config/collectors.xml | 1 + .../Resources/config/debug.xml | 1 + .../Resources/config/profiling.xml | 1 + .../Resources/config/routing.xml | 1 + .../Resources/config/templating_debug.xml | 1 + .../FrameworkBundle/Resources/config/web.xml | 4 +++ .../Resources/config/security_acl.xml | 3 +- .../Resources/config/security_listeners.xml | 24 +++++++++++----- .../Resources/config/security_rememberme.xml | 28 ++++++++++--------- 11 files changed, 46 insertions(+), 22 deletions(-) diff --git a/src/Symfony/Bundle/DoctrineBundle/Resources/config/dbal.xml b/src/Symfony/Bundle/DoctrineBundle/Resources/config/dbal.xml index e72d8a10d470b..87914fb0f4ebb 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Resources/config/dbal.xml +++ b/src/Symfony/Bundle/DoctrineBundle/Resources/config/dbal.xml @@ -21,6 +21,7 @@ + diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/mongodb.xml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/mongodb.xml index 296f54b1615f0..a7ea41f4f8393 100755 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/mongodb.xml +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/mongodb.xml @@ -86,6 +86,7 @@ + @@ -114,6 +115,6 @@ - + \ No newline at end of file diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml index 0042e549f0c30..1dc3159cd8e51 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml @@ -37,6 +37,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml index f3556df5098db..102540da5c896 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml @@ -10,6 +10,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml index 72794e98ff23d..c93ed32fb5822 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml @@ -15,6 +15,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml index 89595deab2f95..1a504a89342b0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml @@ -48,6 +48,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_debug.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_debug.xml index a47d287838b9c..006bd0b3280e0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_debug.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_debug.xml @@ -10,6 +10,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml index 580bff67644a7..07cce83d6b724 100755 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml @@ -15,11 +15,13 @@ + + @@ -27,6 +29,7 @@ + @@ -38,6 +41,7 @@ + %exception_listener.controller% diff --git a/src/Symfony/Bundle/SecurityBundle/Resources/config/security_acl.xml b/src/Symfony/Bundle/SecurityBundle/Resources/config/security_acl.xml index 92736ba14a90a..74cc94babb685 100644 --- a/src/Symfony/Bundle/SecurityBundle/Resources/config/security_acl.xml +++ b/src/Symfony/Bundle/SecurityBundle/Resources/config/security_acl.xml @@ -60,7 +60,7 @@ - + %security.acl.cache.doctrine.prefix% @@ -69,6 +69,7 @@ + diff --git a/src/Symfony/Bundle/SecurityBundle/Resources/config/security_listeners.xml b/src/Symfony/Bundle/SecurityBundle/Resources/config/security_listeners.xml index 9c1de812bc97a..e11c9edb6756d 100644 --- a/src/Symfony/Bundle/SecurityBundle/Resources/config/security_listeners.xml +++ b/src/Symfony/Bundle/SecurityBundle/Resources/config/security_listeners.xml @@ -26,7 +26,7 @@ SSL_CLIENT_S_DN Symfony\Component\Security\Http\Firewall\AnonymousAuthenticationListener - + Symfony\Component\Security\Http\Firewall\SwitchUserListener Symfony\Component\Security\Http\Firewall\LogoutListener @@ -44,9 +44,10 @@ Symfony\Component\Security\Core\Authentication\Provider\AnonymousAuthenticationProvider SomeRandomValue - + + %security.anonymous.key% @@ -68,6 +69,7 @@ + @@ -76,6 +78,7 @@ + @@ -94,6 +97,7 @@ + @@ -104,13 +108,14 @@ - + @@ -120,6 +125,7 @@ + @@ -128,26 +134,28 @@ + - + - + - + + @@ -157,6 +165,7 @@ + @@ -166,6 +175,7 @@ + diff --git a/src/Symfony/Bundle/SecurityBundle/Resources/config/security_rememberme.xml b/src/Symfony/Bundle/SecurityBundle/Resources/config/security_rememberme.xml index 2d3f8583f2ef7..5c06caaecdea5 100644 --- a/src/Symfony/Bundle/SecurityBundle/Resources/config/security_rememberme.xml +++ b/src/Symfony/Bundle/SecurityBundle/Resources/config/security_rememberme.xml @@ -6,47 +6,49 @@ Symfony\Component\Security\Core\Authentication\Provider\RememberMeAuthenticationProvider - + Symfony\Component\Security\Http\Firewall\RememberMeListener Symfony\Component\Security\Core\Authentication\RememberMe\InMemoryTokenProvider - + Symfony\Component\Security\Http\RememberMe\PersistentTokenBasedRememberMeServices Symfony\Component\Security\Http\RememberMe\TokenBasedRememberMeServices - + + - + - + + - - - - - - \ No newline at end of file + + \ No newline at end of file From a25c81476fd0442c628a24630311386a473a6b79 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 25 Feb 2011 23:10:09 +0100 Subject: [PATCH 14/16] Udpate for latest monolog version --- src/Symfony/Bundle/MonologBundle/Logger/Logger.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/MonologBundle/Logger/Logger.php b/src/Symfony/Bundle/MonologBundle/Logger/Logger.php index e8a534837bfa2..814cad02731ac 100644 --- a/src/Symfony/Bundle/MonologBundle/Logger/Logger.php +++ b/src/Symfony/Bundle/MonologBundle/Logger/Logger.php @@ -38,6 +38,6 @@ public function getDebugLogger() public function log($message, $level) { - return $this->addMessage($level, $message); + return $this->addRecord($level, $message); } } From f9be0364bfd90d4c2237ec487fcc8d1831533f4c Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Fri, 25 Feb 2011 23:13:17 +0100 Subject: [PATCH 15/16] Added the DebugHandler when the profiler is activated --- .../Compiler/DebugHandlerPass.php | 39 +++++++++++++++++++ .../{DebugLogger.php => DebugHandler.php} | 2 +- .../Bundle/MonologBundle/MonologBundle.php | 2 + .../Resources/config/monolog.xml | 1 + 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/DebugHandlerPass.php rename src/Symfony/Bundle/MonologBundle/Logger/{DebugLogger.php => DebugHandler.php} (91%) 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 0000000000000..f14eb02e5b8bc --- /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 94423cfb06fb9..c2c54f5bb8ffd 100644 --- a/src/Symfony/Bundle/MonologBundle/Logger/DebugLogger.php +++ b/src/Symfony/Bundle/MonologBundle/Logger/DebugHandler.php @@ -20,7 +20,7 @@ * * @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 49f25f3aa98d8..4cacd3cb1da73 100644 --- a/src/Symfony/Bundle/MonologBundle/MonologBundle.php +++ b/src/Symfony/Bundle/MonologBundle/MonologBundle.php @@ -14,6 +14,7 @@ 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 @@ public function build(ContainerBuilder $container) 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 56ca4b4336b11..645fc164941b3 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 From 0c007d7a5049306475f1b82b02fd3920503c7195 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 25 Feb 2011 23:25:51 +0100 Subject: [PATCH 16/16] [MonologBundle] Fix DebugHandler to match Symfony's interface --- .../Bundle/MonologBundle/Logger/DebugHandler.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/Logger/DebugHandler.php b/src/Symfony/Bundle/MonologBundle/Logger/DebugHandler.php index c2c54f5bb8ffd..843dd93ebe35d 100644 --- a/src/Symfony/Bundle/MonologBundle/Logger/DebugHandler.php +++ b/src/Symfony/Bundle/MonologBundle/Logger/DebugHandler.php @@ -12,7 +12,6 @@ namespace Symfony\Bundle\MonologBundle\Logger; use Monolog\Handler\TestHandler; -use Monolog\Logger; use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; /** @@ -27,7 +26,16 @@ class DebugHandler extends TestHandler implements DebugLoggerInterface */ public function getLogs() { - return $this->messages; + $records = array(); + foreach ($this->records as $record) { + $records[] = array( + 'timestamp' => $record['datetime']->getTimestamp(), + 'message' => $record['message'], + 'priority' => $record['level'], + 'priorityName' => $record['level_name'], + ); + } + return $records; } /** @@ -35,6 +43,8 @@ public function getLogs() */ public function countErrors() { - return count($this->messagesByLevel[Logger::ERROR]); + return isset($this->recordsByLevel[\Monolog\Logger::ERROR]) + ? count($this->recordsByLevel[\Monolog\Logger::ERROR]) + : 0; } }