Log exception using ILogger

Signed-off-by: Patrik Kernstock <info@pkern.at>
This commit is contained in:
Patrik Kernstock 2018-10-05 21:09:13 +02:00
parent f27ce6b5a0
commit 1973556346
2 changed files with 15 additions and 2 deletions

View File

@ -24,6 +24,7 @@ namespace OC\Core\Command\App;
use OC\Installer;
use OCP\App\IAppManager;
use OCP\ILogger;
use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface;
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use Symfony\Component\Console\Command\Command;
@ -38,15 +39,19 @@ class Remove extends Command implements CompletionAwareInterface {
protected $manager;
/** @var Installer */
private $installer;
/** @var ILogger */
private $logger;
/**
* @param IAppManager $manager
* @param Installer $installer
* @param ILogger $logger
*/
public function __construct(IAppManager $manager, Installer $installer) {
public function __construct(IAppManager $manager, Installer $installer, ILogger $logger) {
parent::__construct();
$this->manager = $manager;
$this->installer = $installer;
$this->logger = $logger;
}
protected function configure() {
@ -90,6 +95,10 @@ class Remove extends Command implements CompletionAwareInterface {
$output->writeln($appId . ' disabled');
} catch(\Exception $e) {
$output->writeln('Error: ' . $e->getMessage());
$this->logger->logException($e, [
'app' => 'CLI',
'level' => ILogger::ERROR
]);
return 1;
}
}
@ -99,6 +108,10 @@ class Remove extends Command implements CompletionAwareInterface {
$result = $this->installer->removeApp($appId);
} catch(\Exception $e) {
$output->writeln('Error: ' . $e->getMessage());
$this->logger->logException($e, [
'app' => 'CLI',
'level' => ILogger::ERROR
]);
return 1;
}

View File

@ -65,7 +65,7 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
$application->add(new OC\Core\Command\App\Install());
$application->add(new OC\Core\Command\App\GetPath());
$application->add(new OC\Core\Command\App\ListApps(\OC::$server->getAppManager()));
$application->add(new OC\Core\Command\App\Remove(\OC::$server->getAppManager(), \OC::$server->query(\OC\Installer::class)));
$application->add(new OC\Core\Command\App\Remove(\OC::$server->getAppManager(), \OC::$server->query(\OC\Installer::class), \OC::$server->getLogger()));
$application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Cleanup::class));
$application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Enforce::class));