From 33c381a1e1dd300adfe100015b2b2d2d2da57478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20D?= Date: Sat, 13 Mar 2021 10:01:53 +0100 Subject: [PATCH] * [MOD] Use logger on CLI commands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rubén D --- app/modules/cli/Commands/InstallCommand.php | 13 +++++++++++++ app/modules/cli/definitions.php | 9 +++++++++ lib/Definitions.php | 2 -- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/modules/cli/Commands/InstallCommand.php b/app/modules/cli/Commands/InstallCommand.php index b7179ea9..cf8ae025 100644 --- a/app/modules/cli/Commands/InstallCommand.php +++ b/app/modules/cli/Commands/InstallCommand.php @@ -116,6 +116,8 @@ final class InstallCommand extends CommandBase $force = (bool)$input->getOption('force'); if ($this->configData->isInstalled() && $force === false) { + $this->logger->warning(__u('sysPass is already installed')); + $this->io->warning(__('sysPass is already installed. Use \'--force\' to install it again.')); return self::FAILURE; @@ -132,6 +134,8 @@ final class InstallCommand extends CommandBase }; if (empty($adminPassword)) { + $this->logger->debug(__u('Ask for admin password')); + $adminPassword = $this->io->askHidden(__('Please provide sysPass admin\'s password'), $passNonEmptyValidator); $adminPasswordRepeat = $this->io->askHidden(__('Please provide sysPass admin\'s password again'), $passNonEmptyValidator); @@ -145,6 +149,8 @@ final class InstallCommand extends CommandBase $masterPassword = $input->getOption('masterPassword'); if (empty($masterPassword)) { + $this->logger->debug(__u('Ask for master password')); + $masterPassword = $this->io->askHidden(__('Please provide sysPass master password'), $passNonEmptyValidator); $masterPasswordRepeat = $this->io->askHidden(__('Please provide sysPass master password again'), $passNonEmptyValidator); @@ -158,18 +164,24 @@ final class InstallCommand extends CommandBase $databasePassword = $input->getOption('databasePassword'); if (empty($databasePassword)) { + $this->logger->debug(__u('Ask for database password')); + $databasePassword = $this->io->askHidden(__('Please provide database admin password')); } $language = $input->getOption('language'); if (empty($language)) { + $this->logger->debug(__u('Ask for language')); + $language = $this->io->choice(__('Language'), array_keys(Language::getAvailableLanguages()), 'en_US'); } $install = $this->io->confirm(__('Install sysPass?'), false); if (!$install) { + $this->logger->debug(__u('Installation aborted')); + return self::SUCCESS; } @@ -189,6 +201,7 @@ final class InstallCommand extends CommandBase $this->io->success(__('Installation finished')); + $this->logger->info(__u('Installation finished')); return self::SUCCESS; } catch (InvalidArgumentException $e) { $this->io->error(__($e->getMessage())); diff --git a/app/modules/cli/definitions.php b/app/modules/cli/definitions.php index afbe235a..8aef1ed4 100644 --- a/app/modules/cli/definitions.php +++ b/app/modules/cli/definitions.php @@ -22,7 +22,10 @@ * along with sysPass. If not, see . */ +use Monolog\Handler\StreamHandler; +use Monolog\Logger; use Psr\Container\ContainerInterface; +use Psr\Log\LoggerInterface; use SP\Modules\Cli\Commands\InstallCommand; use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\ArgvInput; @@ -35,6 +38,12 @@ use function DI\create; use function DI\factory; return [ + LoggerInterface::class => function (ContainerInterface $c) { + $logger = $c->get(Logger::class); + $logger->pushHandler(new StreamHandler(LOG_FILE)); + + return $logger; + }, Application::class => create(Application::class), OutputInterface::class => create(ConsoleOutput::class) ->constructor(ConsoleOutput::VERBOSITY_NORMAL, true), diff --git a/lib/Definitions.php b/lib/Definitions.php index a815485b..335e0fed 100644 --- a/lib/Definitions.php +++ b/lib/Definitions.php @@ -25,7 +25,6 @@ use Monolog\Logger; use PHPMailer\PHPMailer\PHPMailer; use Psr\Container\ContainerInterface; -use Psr\Log\LoggerInterface; use SP\Config\Config; use SP\Config\ConfigData; use SP\Core\Acl\Acl; @@ -94,7 +93,6 @@ return [ ->constructor(true), Logger::class => create(Logger::class) ->constructor('syspass'), - LoggerInterface::class => get(Logger::class), AccountAclService::class => autowire(AccountAclService::class), \GuzzleHttp\Client::class => create(GuzzleHttp\Client::class) ->constructor(factory([Client::class, 'getOptions'])),