Skip to content
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

Add the connection name to logs #1687

Open
sylfabre opened this issue Jul 25, 2023 · 3 comments
Open

Add the connection name to logs #1687

sylfabre opened this issue Jul 25, 2023 · 3 comments

Comments

@sylfabre
Copy link

Hello

First, thank you for this amazing package!

I'm using the bundle with several connections and here is a suggestion after playing with logs.

Logs with the dedicated Doctrine\DBAL\Logging\Middleware are lacking the connection name used by the bundle.
Right now, it is impossible to know which connection is related to a given log.

Thanks!

@dmaicher
Copy link
Contributor

I think this would make sense 👍 But this would probably involve contributing to the DBAL Middleware code to make it possible to pass additional information (like the connection name) into the logging context?

@ostrolucky
Copy link
Member

We could perhaps inject logger to Middleware with certain monolog processor attached

@dmaicher
Copy link
Contributor

dmaicher commented Aug 2, 2023

Or maybe a psr logger decorator could also do the job? 🤔

use Psr\Log\AbstractLogger;
use Psr\Log\LoggerInterface;

class ConnectionNameAwareLogger extends AbstractLogger
{
    public function __construct(private LoggerInterface $decoratedLogger, private string $connectionName)
    {
    }

    public function log($level, \Stringable|string $message, array $context = []): void
    {
        $this->decoratedLogger->log($level, $message, ['doctrine.dbal.connection_name' => $this->connectionName] + $context);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants