From 4461b79e781b297f0ed7bb5b2a0d86069e7151d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Baptiste=20Clavi=C3=A9?= Date: Fri, 5 Jan 2018 14:21:25 +0100 Subject: [PATCH 1/3] Add an option to set the logger channel --- src/DependencyInjection/Configuration.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index d25423c..8115858 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -47,6 +47,11 @@ private function addAmqpNode(NodeDefinition $root) ->isRequired() ->end() + ->scalarNode('logger_channel') + ->info('Logger channel to use when a logger is required') + ->defaultValue('amqp') + ->end() + ->arrayNode('connections') ->info('Connections to AMQP to use') ->useAttributeAsKey('name') From 21c390209358b5e28403b2128f8d09fcf2d4d926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Baptiste=20Clavi=C3=A9?= Date: Fri, 5 Jan 2018 14:37:08 +0100 Subject: [PATCH 2/3] Dynamically change the channel name for the logger tags --- src/DependencyInjection/WisemblyAmqpExtension.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/DependencyInjection/WisemblyAmqpExtension.php b/src/DependencyInjection/WisemblyAmqpExtension.php index aa637a7..693f352 100644 --- a/src/DependencyInjection/WisemblyAmqpExtension.php +++ b/src/DependencyInjection/WisemblyAmqpExtension.php @@ -20,6 +20,8 @@ use Wisembly\AmqpBundle\Broker\PeclBroker; use Wisembly\AmqpBundle\Processor\ProcessFactory; +use Wisembly\AmqpBundle\Processor\ConsumerFactory; +use Wisembly\AmqpBundle\Processor\CommandProcessor; /** * This is the class that loads and manages your bundle configuration @@ -59,6 +61,18 @@ public function load(array $configs, ContainerBuilder $container) $container->registerForAutoconfiguration(BrokerInterface::class) ->addTag('wisembly.amqp.broker') ; + + // dynamically change the monolog.logger tag + foreach ([ConsumerFactory::class, CommandProcessor::class] as $service) { + $def = $container->getDefinition($service); + $tags = $def->getTag('monolog.logger'); + $def->clearTag('monolog.logger'); + + foreach ($tags as $attributes) { + $attributes['channel'] = $config['logger_channel']; + $def->addTag('monolog.logger', $attributes); + } + } } public function getConfig(array $configs): array From f132c1eddc338abbbaceda7c082319b545b191d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Baptiste=20Clavi=C3=A9?= Date: Fri, 5 Jan 2018 14:45:43 +0100 Subject: [PATCH 3/3] Add test for logger channel changing feature --- .../WisemblyAmqpExtensionTest.php | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/DependencyInjection/WisemblyAmqpExtensionTest.php b/tests/DependencyInjection/WisemblyAmqpExtensionTest.php index 847c32d..c78d00f 100644 --- a/tests/DependencyInjection/WisemblyAmqpExtensionTest.php +++ b/tests/DependencyInjection/WisemblyAmqpExtensionTest.php @@ -8,9 +8,13 @@ use Wisembly\AmqpBundle\GatesBag; use Wisembly\AmqpBundle\Connection; use Wisembly\AmqpBundle\UriConnection; + use Wisembly\AmqpBundle\BrokerInterface; use Wisembly\AmqpBundle\Broker\PeclBroker; +use Wisembly\AmqpBundle\Processor\ConsumerFactory; +use Wisembly\AmqpBundle\Processor\CommandProcessor; + class WisemblyAmqpExtensionTest extends TestCase { public function test_it_can_be_instantiated() @@ -116,7 +120,23 @@ public function test_it_picks_the_default_connection_if_none_specified() } } - private function getContainer(array $config = []) + public function test_it_changes_the_monolog_tag() + { + $container = $this->getContainer([ + 'logger_channel' => 'foo' + ]); + + foreach ([CommandProcessor::class, ConsumerFactory::class] as $service) { + $def = $container->getDefinition($service); + $tags = $def->getTag('monolog.logger'); + + foreach ($tags as $attributes) { + $this->assertSame('foo', $attributes['channel']); + } + } + } + + private function getContainer(array $config = []): ContainerBuilder { $broker = $this->prophesize(BrokerInterface::class)->reveal();