-
-
Notifications
You must be signed in to change notification settings - Fork 477
feat: add logging middleware registration per connection with logger service #2156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add logging middleware registration per connection with logger service #2156
Conversation
| // Register logging middlewares only when a logger service is available | ||
| if (! $container->has('logger')) { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be moved below? Otherwise doctrine.middleware tag is not being added to logging middleware
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not really solved. Line 1475 is still skipped if logger doesn't exist, while that is not the case without this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, should be resolved now at 30d17ab
| $id = sprintf('doctrine.dbal.logging_middleware.%s', $connName); | ||
| $child = new ChildDefinition('doctrine.dbal.logging_middleware'); | ||
| $child->addTag('doctrine.middleware', ['connection' => $connName, 'priority' => 10]); | ||
| $child->addTag('monolog.logger', ['channel' => sprintf('doctrine.%s', $connName)]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should change channel according connection name
| // Register a dummy logger service to enable logging middleware registration | ||
| $container->setDefinition('logger', (new Definition('\stdClass'))->setPublic(true)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why are these needed. Probably because of my other comment.
| $loggingMiddlewareAbstractDef->addTag('doctrine.middleware', ['connection' => $connName, 'priority' => 10]); | ||
|
|
||
| // Create a child service with a dedicated Monolog channel | ||
| $id = sprintf('doctrine.dbal.logging_middleware.%s', $connName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for a variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor at 03dde76
|
@ostrolucky I think that all covered. If I remove from the test the part of $container->setDefinition('logger', (new Definition('\stdClass'))->setPublic(true)) It will fail the tests. Let me know if you need that I modify more things |
|
I don't really see how this solves #1687. Could you explain which part of it is making it log the connection id? |
As far I understand, the part of the implementation that enables logging the connection ID is in the MiddlewaresPass compiler pass which processes all services tagged with doctrine.middleware. For each connection creates child service definitions for middlewares that are applicable to that connection. If a middleware implements the ConnectionNameAwareInterface, it calls setConnectionName($name) on the child service instance passing the connection name. So, In this case, the Doctrine\DBAL\Logging\Middleware (used for the logging middleware) updating to implement ConnectionNameAwareInterface. When setConnectionName is called, the middleware stores the connection name and includes it in the log context for all logging operations (queries, executions, transactions). This ensures that logs from different connections can be distinguished by the connection name, solving the issue of logs lacking the connection identifier. The relevant code is in MiddlewaresPass.php, specifically the loop that creates child definitions and calls setConnectionName if the interface is implemented. |
What does this sentence even mean? This PR didn't touch |
|
I was starting to look into this myself, but then I remembered I had an LLM, so I asked it if this is AI slop or not. Here is its response. Based on this, I don't feel like looking deeper into this. @shakaran , if we are wrong about this, please demonstrate it by creating a test application that uses commit 508856f and show us the logs. |
Related to #1687