Skip to content

Commit

Permalink
Add further logging output
Browse files Browse the repository at this point in the history
  • Loading branch information
digilist committed Jan 16, 2018
1 parent 0dc93ec commit 00df57b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/Dumper/Context/AbstractDumperContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,13 @@ private function createLogger(OutputInterface $applicationOutput)
return new NullLogger();
}

$minLevel = Logger::INFO;
if ($applicationOutput->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) {
$minLevel = Logger::DEBUG;
}

$logger = new Logger('snakedumper');
$logger->pushHandler(new StreamHandler(fopen('php://stderr', 'w')));
$logger->pushHandler(new StreamHandler(fopen('php://stderr', 'w'), $minLevel));

return $logger;
}
Expand Down
10 changes: 9 additions & 1 deletion src/Dumper/Sql/DataLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\DBAL\Query\QueryBuilder;
use Doctrine\DBAL\Schema\Table;
use InvalidArgumentException;
use Psr\Log\LoggerInterface;

/**
* This class helps to query the appropriate data that should be dumped.
Expand All @@ -20,13 +21,19 @@ class DataLoader
* @var ConnectionHandler
*/
private $connectionHandler;
/**
* @var LoggerInterface
*/
private $logger;

/**
* @param ConnectionHandler $connectionHandler
* @param LoggerInterface $logger
*/
public function __construct(ConnectionHandler $connectionHandler)
public function __construct(ConnectionHandler $connectionHandler, LoggerInterface $logger)
{
$this->connectionHandler = $connectionHandler;
$this->logger = $logger;
}

/**
Expand All @@ -43,6 +50,7 @@ public function executeSelectQuery(TableConfiguration $tableConfig, Table $table
{
list($query, $parameters) = $this->buildSelectQuery($tableConfig, $table, $harvestedValues);

$this->logger->debug('Executing select query' . $query);
$result = $this->connectionHandler->getConnection()->prepare($query);
$result->execute($parameters);

Expand Down
3 changes: 2 additions & 1 deletion src/Dumper/Sql/Dumper/TableContentsDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __construct(SqlDumperContext $context) {
$this->dumpOutput = $context->getDumpOutput();
$this->logger = $context->getLogger();

$this->dataLoader = new DataLoader($this->connectionHandler);
$this->dataLoader = new DataLoader($this->connectionHandler, $context->getLogger());
}

/**
Expand Down Expand Up @@ -108,6 +108,7 @@ private function dumpTableContent(Table $table, TableConfiguration $tableConfig)
$bufferCount = 0; // number of rows in buffer
$buffer = array(); // array to buffer rows

$this->logger->info('Querying table ' . $table->getName());
$rowCount = $this->dataLoader->countRows($tableConfig, $table, $this->harvestedValues);
$result = $this->dataLoader->executeSelectQuery($tableConfig, $table, $this->harvestedValues);

Expand Down
3 changes: 2 additions & 1 deletion src/Dumper/Sql/Tests/DataLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Digilist\SnakeDumper\Dumper\Sql\DataLoader;
use Doctrine\DBAL\Query\QueryBuilder;
use Doctrine\DBAL\Schema\Table;
use Psr\Log\NullLogger;

class DataLoaderTest extends AbstractSqlTest
{
Expand All @@ -30,7 +31,7 @@ public function setUp()
parent::setUp();

$dbConfig = new DatabaseConfiguration(['connection' => $this->connection]);
$this->dataLoader = new DataLoader(new ConnectionHandler($dbConfig));
$this->dataLoader = new DataLoader(new ConnectionHandler($dbConfig), new NullLogger());

$refl = new \ReflectionObject($this->dataLoader);
$createSelectQueryBuilder = $refl->getMethod('createSelectQueryBuilder');
Expand Down

0 comments on commit 00df57b

Please sign in to comment.