Skip to content

Add services tagged with 'doctrine.dbal.logger' to the connection's chain logger#692

Closed
renan wants to merge 6 commits intodoctrine:masterfrom
renan:tag-dbal-logger
Closed

Add services tagged with 'doctrine.dbal.logger' to the connection's chain logger#692
renan wants to merge 6 commits intodoctrine:masterfrom
renan:tag-dbal-logger

Conversation

@renan
Copy link
Copy Markdown

@renan renan commented Aug 30, 2017

I've run into a use case where I need more than one SQLLogger on my application. I could've simply redefined the whole service that is provided by Doctrine Bundle but thought supporting this use case in the Bundle itself would be more beneficial as it opens other bundles to also hook into Doctrine SQL Logging.

Services that are tagged with doctrine.dbal.logger are added to all connections.

Copy link
Copy Markdown
Contributor

@mikeSimonson mikeSimonson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this is good to go minus the wording of the error message.

I just want @stof to look a it to confirm that there would be no performance penality.

Thanks for the PR

@renan
Copy link
Copy Markdown
Author

renan commented Aug 30, 2017

The feedback has been applied.

I undid all changes to DoctrineExtension so the previous added overhead is gone.

If the configuration is using a chain logger it will simply append the new loggers into it. Otherwise it will wrap the existing logger plus the new loggers into a new chain.

}
}

private function ensureIsValidServiceDefinition(ContainerBuilder $container, string $serviceId): void
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed?

I have never noticed any other doing this much for detecting miss configurations of services and symfony it self is happy to fail when you try to retrieve the service from the container.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyone have a comment on this?

We don't have this anywhere else neither have i seen others do it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep it's not needed

@kimhemsoe kimhemsoe self-assigned this Nov 25, 2017
@kimhemsoe kimhemsoe added this to the 1.8.2 milestone Nov 25, 2017
@kimhemsoe
Copy link
Copy Markdown
Member

@renan Is it possible for you to have a go at resolving the conflict?

$chainId = self::BASE_CHAIN_NAME . '.' . $connectionName;

$chainReference = new Reference($chainId);
$chainDefinition = new Definition(self::BASE_CHAIN_NAME);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't there be LoggerChain::class?

I am getting error Symfony\Component\DependencyInjection\Exception\InvalidArgumentException: "'doctrine.dbal.logger.chain'" is not a valid class name for the "doctrine.dbal.logger.chain.default" service. with self::BASE_CHAIN_NAME

@kimhemsoe kimhemsoe modified the milestones: 1.8.2, 1.9.1 Apr 18, 2018
@kimhemsoe kimhemsoe removed this from the 1.9.2 milestone Oct 30, 2018
@ostrolucky ostrolucky self-assigned this Apr 6, 2019
@ostrolucky
Copy link
Copy Markdown
Member

Hey! Thank you for your contribution. I've reviewed this PR in detail as part of #EUFOSSA and I'm afraid this is not mergeable in current state because of following reasons:

  • there are 3 feedback comments left unaddressed
  • it disregards current dbal.connections.*.logging option. This is pretty big one and can create lot of confusion.
  • it's undocumented and too implicit, while custom service definition is pretty explicit and easy to do via decorator
  • it creates ChainLogger even if there is only single logger
  • it adds too much complexity while less complex solution would be to contribute option to inject iterable of loggers into LoggerChain and utilize here !tagged option available since Symfony 3.4. In such case we could just make our own definitions tag and always injected services tagged as such.

@ostrolucky ostrolucky closed this Apr 6, 2019
@ostrolucky ostrolucky added the ⭐️ EUFOSSA Hackathon https://symfony.com/blog/the-symfony-and-api-platform-hackathon-is-coming label Apr 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⭐️ EUFOSSA Hackathon https://symfony.com/blog/the-symfony-and-api-platform-hackathon-is-coming Feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants