Skip to content

Commit

Permalink
Merge pull request #5 from claroline/update_logger
Browse files Browse the repository at this point in the history
Update logger
  • Loading branch information
ngodfraind committed Mar 4, 2015
2 parents 6957f44 + dbec4fa commit 3fc8dc1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
12 changes: 8 additions & 4 deletions Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

namespace Claroline\MigrationBundle\Command;

use Psr\Log\LogLevel;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Logger\ConsoleLogger;
use Symfony\Component\Console\Output\OutputInterface;

abstract class AbstractCommand extends ContainerAwareCommand
Expand Down Expand Up @@ -44,11 +46,13 @@ function ($argument) {
protected function getManager(OutputInterface $output)
{
$manager = $this->getContainer()->get('claroline.migration.manager');
$manager->setLogger(
function ($message) use ($output) {
$output->writeln($message);
}
$verbosityLevelMap = array(
LogLevel::NOTICE => OutputInterface::VERBOSITY_NORMAL,
LogLevel::INFO => OutputInterface::VERBOSITY_NORMAL,
LogLevel::DEBUG => OutputInterface::VERBOSITY_NORMAL
);
$consoleLogger = new ConsoleLogger($output, $verbosityLevelMap);
$manager->setLogger($consoleLogger);

return $manager;
}
Expand Down
21 changes: 3 additions & 18 deletions Manager/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Claroline\MigrationBundle\Manager;

use Claroline\InstallationBundle\Log\LoggableTrait;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Claroline\MigrationBundle\Generator\Generator;
use Claroline\MigrationBundle\Generator\Writer;
Expand All @@ -21,10 +22,11 @@
*/
class Manager
{
use LoggableTrait;

private $generator;
private $writer;
private $migrator;
private $logger;

/**
* Constructor.
Expand All @@ -44,16 +46,6 @@ public function __construct(
$this->writer = $writer;
}

/**
* Sets a logger for this class's operations.
*
* @param \Closure $logger
*/
public function setLogger(\Closure $logger)
{
$this->logger = $logger;
}

/**
* Generates bundle migrations classes for all the available driver platforms.
*
Expand Down Expand Up @@ -179,11 +171,4 @@ private function doMigrate(Bundle $bundle, $version, $direction)
"Done: bundle is now at version {$currentVersion}"
);
}

private function log($message)
{
if ($log = $this->logger) {
$log($message);
}
}
}

0 comments on commit 3fc8dc1

Please sign in to comment.