phoenix
phoenix copied to clipboard
Add the connection name to logs
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!
I think this would make sense :+1: 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?
We could perhaps inject logger to Middleware with certain monolog processor attached
Or maybe a psr logger decorator could also do the job? :thinking:
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);
}
}