Skip to content

Commit f052b31

Browse files
Added the handler_class option to customize a handler while keeping its original type.
1 parent 26a29b9 commit f052b31

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

config/schema/monolog-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
<xsd:attribute name="slack-team" type="xsd:string" />
9696
<xsd:attribute name="region" type="xsd:string" />
9797
<xsd:attribute name="enabled" type="xsd:boolean" />
98+
<xsd:attribute name="handler_class" type="xsd:string" />
9899
</xsd:complexType>
99100

100101
<xsd:simpleType name="level">

src/DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ public function getConfigTreeBuilder(): TreeBuilder
661661
->end()
662662
->scalarNode('formatter')->end()
663663
->booleanNode('nested')->defaultFalse()->end()
664+
->scalarNode('handler_class')->defaultNull()->end()
664665
->end();
665666

666667
$this->addGelfSection($handlerNode);

src/DependencyInjection/MonologExtension.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,15 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
166166
return $handlerId;
167167
}
168168

169-
$handlerClass = $this->getHandlerClassByType($handler['type']);
169+
if (null !== $handler['handler_class']) {
170+
$handlerClass = $handler['handler_class'];
171+
if (!class_exists($handlerClass)) {
172+
throw new \RuntimeException(sprintf('The handler class "%s" does not exist.', $handlerClass));
173+
}
174+
} else {
175+
$handlerClass = $this->getHandlerClassByType($handler['type']);
176+
}
177+
170178
$definition = new Definition($handlerClass);
171179

172180
if ($handler['include_stacktraces']) {

0 commit comments

Comments
 (0)