Added support of custom handlers defined as services
This commit is contained in:
parent
9d3acf3073
commit
5aaf8bc1b1
@ -52,6 +52,7 @@ class Configuration
|
||||
->then(function($v) { return strtolower($v); })
|
||||
->end()
|
||||
->end()
|
||||
->scalarNode('id')->end()
|
||||
->scalarNode('level')->defaultValue('DEBUG')->end()
|
||||
->booleanNode('bubble')->defaultFalse()->end()
|
||||
->scalarNode('path')->end() // stream specific
|
||||
@ -65,6 +66,10 @@ class Configuration
|
||||
->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 'service' === $v['type'] && !isset($v['id']); })
|
||||
->thenInvalid('The id has to be specified to use a service as handler')
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
|
@ -81,6 +81,10 @@ class MonologExtension extends Extension
|
||||
$handler['level'] = is_int($handler['level']) ? $handler['level'] : constant('Monolog\Logger::'.strtoupper($handler['level']));
|
||||
|
||||
switch ($handler['type']) {
|
||||
case 'service':
|
||||
$container->setAlias($handlerId, $handler['id']);
|
||||
return $handlerId;
|
||||
|
||||
case 'stream':
|
||||
if (!isset($handler['path'])) {
|
||||
$handler['path'] = '%kernel.logs_dir%/%kernel.environment%.log';
|
||||
@ -108,6 +112,7 @@ class MonologExtension extends Extension
|
||||
$handler['bubble'],
|
||||
));
|
||||
break;
|
||||
|
||||
default:
|
||||
// Handler using the constructor of AbstractHandler without adding their own arguments
|
||||
$definition->setArguments(array(
|
||||
|
@ -22,6 +22,7 @@
|
||||
<xsd:attribute name="level" type="level" />
|
||||
<xsd:attribute name="bubble" type="xsd:boolean" />
|
||||
<xsd:attribute name="path" type="xsd:string" />
|
||||
<xsd:attribute name="id" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" use="required">
|
||||
<xsd:attribute name="action-level" type="level" />
|
||||
<xsd:attribute name="buffer-size" type="xsd:integer" />
|
||||
|
Reference in New Issue
Block a user