diff --git a/DependencyInjection/MonologExtension.php b/DependencyInjection/MonologExtension.php
index e1ac10a8..5cbbf72a 100644
--- a/DependencyInjection/MonologExtension.php
+++ b/DependencyInjection/MonologExtension.php
@@ -933,6 +933,8 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
$definition->addTag('kernel.reset', ['method' => 'reset']);
}
+ $definition->addTag('monolog.handler');
+
$container->setDefinition($handlerId, $definition);
return $handlerId;
diff --git a/HandlerLifecycleManager.php b/HandlerLifecycleManager.php
new file mode 100644
index 00000000..0ddcc956
--- /dev/null
+++ b/HandlerLifecycleManager.php
@@ -0,0 +1,27 @@
+handlers = $handlers;
+ }
+
+ public function close()
+ {
+ foreach ($this->handlers as $handler) {
+ $handler->close();
+ }
+ }
+}
diff --git a/MonologBundle.php b/MonologBundle.php
index ba159196..19f976ff 100644
--- a/MonologBundle.php
+++ b/MonologBundle.php
@@ -52,4 +52,14 @@ public static function includeStacktraces(HandlerInterface $handler)
$formatter->includeStacktraces();
}
}
+
+ public function shutdown()
+ {
+ parent::shutdown();
+
+ $handlerManager = $this->container->get('monolog.handler_manager');
+
+ $handlerManager->close();
+ }
+
}
diff --git a/Resources/config/monolog.xml b/Resources/config/monolog.xml
index 3f62ed57..90c6dcee 100644
--- a/Resources/config/monolog.xml
+++ b/Resources/config/monolog.xml
@@ -40,5 +40,9 @@
+
+
+
+
diff --git a/Tests/DependencyInjection/MonologExtensionTest.php b/Tests/DependencyInjection/MonologExtensionTest.php
index fe408186..18d6f569 100644
--- a/Tests/DependencyInjection/MonologExtensionTest.php
+++ b/Tests/DependencyInjection/MonologExtensionTest.php
@@ -89,6 +89,16 @@ public function testLoadWithNestedHandler()
$this->assertDICConstructorArguments($handler, ['/tmp/symfony.log', \Monolog\Logger::ERROR, false, 0666, false]);
}
+ public function testTagsAllHandlersCreated()
+ {
+ $container = $this->getContainer([['handlers' => [
+ 'custom' => ['type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => false, 'level' => 'ERROR', 'file_permission' => '0666'],
+ 'nested' => ['type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => false, 'level' => 'ERROR', 'file_permission' => '0666', 'nested' => true]
+ ]]]);
+ $taggedHandlers = $container->findTaggedServiceIds('monolog.handler');
+ $this->assertCount(2, $taggedHandlers);
+ }
+
public function testLoadWithServiceHandler()
{
$container = $this->getContainer(