Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DependencyInjection/Compiler/MappingPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ private function getClientParams(array $connection, array $manager, ContainerBui
$params['connectionParams']['auth'] = array_values($connection['auth']);
}

if ($manager['debug']) {
if ($manager['debug']['enabled'] === true) {
$params['logging'] = true;
$params['logPath'] = $container->getParameter('es.logging.path');
$params['logLevel'] = LogLevel::WARNING;
$params['logLevel'] = $manager['debug']['level'];
$params['traceObject'] = new Reference('es.logger.trace');
}

Expand Down
33 changes: 30 additions & 3 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace ONGR\ElasticsearchBundle\DependencyInjection;

use Psr\Log\LogLevel;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
Expand Down Expand Up @@ -131,9 +132,35 @@ private function getManagersNode()
->isRequired()
->info('Sets connection for manager.')
->end()
->booleanNode('debug')
->info('Enables logging.')
->defaultFalse()
->arrayNode('debug')
->info('Enables logging')
->addDefaultsIfNotSet()
->beforeNormalization()
->ifTrue(
function ($v) {
return is_bool($v);
}
)
->then(
function ($v) {
return ['enabled' => $v];
}
)
->end()
->children()
->booleanNode('enabled')
->info('enables logging')
->defaultFalse()
->end()
->scalarNode('level')
->info('Sets psr logging level')
->defaultValue(LogLevel::WARNING)
->validate()
->ifNotInArray((new \ReflectionClass('Psr\Log\LogLevel'))->getConstants())
->thenInvalid('Invalid Psr log level.')
->end()
->end()
->end()
->end()
->booleanNode('readonly')
->info('Sets manager to read only state.')
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/ONGRElasticsearchExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private function addDataCollectorDefinition(array $config, ContainerBuilder $con
private function isDebugSet(array $config)
{
foreach ($config['managers'] as $manager) {
if ($manager['debug']) {
if ($manager['debug']['enabled'] === true) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ public function testContainerDefaultParams()
$expectedManagers = [
'default' => [
'connection' => 'default',
'debug' => true,
'debug' => [
'enabled' => true,
'level' => 'warning',
],
'readonly' => false,
'mappings' => [
'AcmeTestBundle',
Expand All @@ -111,13 +114,19 @@ public function testContainerDefaultParams()
],
'bar' => [
'connection' => 'bar',
'debug' => false,
'debug' => [
'enabled' => false,
'level' => 'warning',
],
'readonly' => false,
'mappings' => ['ONGRElasticsearchBundle'],
],
'readonly' => [
'connection' => 'default',
'debug' => true,
'debug' => [
'enabled' => true,
'level' => 'warning',
],
'readonly' => true,
'mappings' => ['AcmeTestBundle'],
],
Expand Down
5 changes: 4 additions & 1 deletion Tests/Unit/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public function getTestConfigurationData()
'managers' => [
'acme' => [
'connection' => 'acme',
'debug' => false,
'debug' => [
'enabled' => false,
'level' => 'warning',
],
'readonly' => false,
'mappings' => ['AcmeTestBundle'],
],
Expand Down
17 changes: 13 additions & 4 deletions Tests/Unit/DependencyInjection/ElasticsearchExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public function getData()
'managers' => [
'test' => [
'connection' => 'test2',
'debug' => true,
'debug' => [
'enabled' => true,
'level' => 'warning',
],
'readonly' => false,
'mappings' => ['testBundle'],
],
Expand All @@ -56,7 +59,10 @@ public function getData()
$expectedManagers = [
'test' => [
'connection' => 'test2',
'debug' => true,
'debug' => [
'enabled' => true,
'level' => 'warning',
],
'readonly' => false,
'mappings' => ['testBundle'],
],
Expand All @@ -77,7 +83,7 @@ public function getData()
'managers' => [
'test' => [
'connection' => 'test2',
'debug' => false,
'debug' => true,
'readonly' => false,
'mappings' => ['testBundle'],
],
Expand All @@ -88,7 +94,10 @@ public function getData()
$expectedManagers = [
'test' => [
'connection' => 'test2',
'debug' => false,
'debug' => [
'enabled' => true,
'level' => 'warning',
],
'readonly' => false,
'mappings' => ['testBundle'],
],
Expand Down