Skip to content

Commit

Permalink
set logger in connection factory
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Green committed Feb 9, 2015
1 parent 7affd65 commit c36410b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Connectors/ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Database\Query\Grammars\PostgresGrammar;
use Database\Query\Grammars\SqlServerGrammar;
use Database\Query\Grammars\SQLiteGrammar;
use Database\QueryLogger;
use Psr\Log\LoggerInterface;

/**
* Class ConnectionFactory
Expand Down Expand Up @@ -41,12 +43,18 @@ class ConnectionFactory implements ConnectionFactoryInterface
*/
protected $connectionClassName = 'Database\Connection';

/**
* @var LoggerInterface
*/
protected $logger;

public function __construct($connectionClassName = null)
public function __construct($connectionClassName = null, LoggerInterface $logger = null)
{
if ($connectionClassName) {
$this->connectionClassName = $connectionClassName;
}

$this->logger = $logger ?: new QueryLogger();
}

/**
Expand Down Expand Up @@ -100,7 +108,8 @@ protected function createSingleConnection(array $config, $lazy)
$connection
->setExceptionHandler(new ExceptionHandler($logSafeParams))
->setQueryGrammar($this->createQueryGrammar($config['driver']))
->setTablePrefix(isset($config['prefix']) ? $config['prefix'] : '');
->setTablePrefix(isset($config['prefix']) ? $config['prefix'] : '')
->setLogger($this->logger);

if(!$lazy)
{
Expand Down

0 comments on commit c36410b

Please sign in to comment.