Skip to content

Commit

Permalink
minor #28 Made log more flexible (lyrixx)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.1.x-dev branch.

Discussion
----------

Made log more flexible

Commits
-------

e150e7e Made log more flexible
  • Loading branch information
lyrixx committed Sep 1, 2014
2 parents 26392b7 + e150e7e commit 655749f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Cli/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Application extends BaseApplication

private $api;
private $apiConfig;
private $enableLog;
private $logFile;

public function __construct()
{
Expand All @@ -51,13 +51,12 @@ public function getApi()
}
$this->api = new Api($config);

if ($this->enableLog) {
if ($this->logFile) {
if (!class_exists('Monolog\Logger')) {
throw new \InvalidArgumentException('You must include monolog if you want to log (run "composer install --dev")');
}

$logger = new Logger('insight');
$logger->pushHandler(new StreamHandler(getcwd().'/insight.log', Logger::DEBUG));
$logger->pushHandler(new StreamHandler($this->logFile, Logger::DEBUG));

$this->api->setLogger($logger);
}
Expand All @@ -72,7 +71,7 @@ protected function getDefaultInputDefinition()
$definition->addOption(new InputOption('api-token', null, InputOption::VALUE_REQUIRED, 'Your api token.'));
$definition->addOption(new InputOption('user-uuid', null, InputOption::VALUE_REQUIRED, 'Your user uuid.'));
$definition->addOption(new InputOption('api-endpoint', null, InputOption::VALUE_REQUIRED, 'The api endpoint.'));
$definition->addOption(new InputOption('log', null, InputOption::VALUE_NONE, 'Add some log capability.'));
$definition->addOption(new InputOption('log', null, InputOption::VALUE_OPTIONAL, 'Add some log capability. Specify a log file if you want to change the log location.'));

return $definition;
}
Expand Down Expand Up @@ -134,7 +133,9 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI

$this->apiConfig = array_merge($this->apiConfig, $newConfig);

$this->enableLog = false !== $input->getParameterOption('--log');
if (false !== $input->getParameterOption('--log')) {
$this->logFile = $input->getParameterOption('--log') ?: getcwd().'/insight.log';
}

return parent::doRunCommand($command, $input, $output);
}
Expand Down

0 comments on commit 655749f

Please sign in to comment.