Skip to content

Commit

Permalink
Check for database connection during logger creation instead of dsn (#…
Browse files Browse the repository at this point in the history
…804)

Resolves #803
  • Loading branch information
M-arcus authored Aug 8, 2024
1 parent 9f8b001 commit 1549c12
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Resources/config/services/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<service id="Kiener\MolliePayments\Service\Logger\MollieLoggerFactory" class="Kiener\MolliePayments\Service\Logger\MollieLoggerFactory">
<argument type="service" id="Kiener\MolliePayments\Service\SettingsService"/>
<argument>%kernel.logs_dir%/mollie_%kernel.environment%.log</argument>
<argument>%env(DATABASE_URL)%</argument>
<argument type="service" id="Doctrine\DBAL\Connection"/>
</service>

<service id="mollie_payments.logger" class="Monolog\Logger">
Expand Down
13 changes: 7 additions & 6 deletions src/Service/Logger/MollieLoggerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Kiener\MolliePayments\Service\Logger;

use Doctrine\DBAL\Connection;
use Kiener\MolliePayments\Service\Logger\Processors\AnonymousWebProcessor;
use Kiener\MolliePayments\Service\Logger\Services\URLAnonymizer;
use Kiener\MolliePayments\Service\SettingsService;
Expand Down Expand Up @@ -31,29 +32,29 @@ class MollieLoggerFactory
private $filename;

/**
* @var string
* @var Connection
*/
private $dsn;
private $connection;


/**
* @param SettingsService $settingsService
* @param string $filename
* @param string $dsn
* @param Connection $connection
*/
public function __construct(SettingsService $settingsService, string $filename, string $dsn)
public function __construct(SettingsService $settingsService, string $filename, Connection $connection)
{
$this->settingsService = $settingsService;
$this->filename = $filename;
$this->dsn = $dsn;
$this->connection = $connection;
}

/**
* @return LoggerInterface
*/
public function createLogger(): LoggerInterface
{
if ($this->dsn === '' || $this->dsn === 'mysql://_placeholder.test') {
if (!$this->connection->isConnected()) {
// deployment server without database
return new Logger(self::CHANNEL);
}
Expand Down

0 comments on commit 1549c12

Please sign in to comment.