From ba3f4f118e8c48a23dcffa723e38439f0b9b7df9 Mon Sep 17 00:00:00 2001 From: Thomas Pulzer Date: Fri, 22 Jul 2016 11:44:19 +0200 Subject: Changed logtype to file instead of owncloud. - Updated the config sample to point to log_type='file' - Renamed the Class for logfile logging to File in namespace 'OC\Log\'. Changed the occurrences of 'OC\Log\Owncloud' to 'OC\Log\File'. - Renamed the Class for log:file command to File in namespace 'OC\Core\Command\Log\File'. Changed registration of the command to use 'OC\Core\Command\Log\File'. - Changed default Syslog tag to Nextcloud - Retained backwards compatibility for configs with 'logtype' => 'owncloud' - Adjusted tests for the new file log. Closes #490. --- core/Command/Log/File.php | 128 ++++++++++++++++++++++++++++++++++++++++++ core/Command/Log/Manage.php | 4 +- core/Command/Log/OwnCloud.php | 126 ----------------------------------------- 3 files changed, 130 insertions(+), 128 deletions(-) create mode 100644 core/Command/Log/File.php delete mode 100644 core/Command/Log/OwnCloud.php (limited to 'core/Command/Log') diff --git a/core/Command/Log/File.php b/core/Command/Log/File.php new file mode 100644 index 00000000000..ec490237400 --- /dev/null +++ b/core/Command/Log/File.php @@ -0,0 +1,128 @@ + + * @author Thomas Pulzer + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OC\Core\Command\Log; + +use \OCP\IConfig; + +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + +class File extends Command { + + /** @var IConfig */ + protected $config; + + public function __construct(IConfig $config) { + $this->config = $config; + parent::__construct(); + } + + protected function configure() { + $this + ->setName('log:file') + ->setDescription('manipulate logging backend') + ->addOption( + 'enable', + null, + InputOption::VALUE_NONE, + 'enable this logging backend' + ) + ->addOption( + 'file', + null, + InputOption::VALUE_REQUIRED, + 'set the log file path' + ) + ->addOption( + 'rotate-size', + null, + InputOption::VALUE_REQUIRED, + 'set the file size for log rotation, 0 = disabled' + ) + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) { + $toBeSet = []; + + if ($input->getOption('enable')) { + $toBeSet['log_type'] = 'file'; + } + + if ($file = $input->getOption('file')) { + $toBeSet['logfile'] = $file; + } + + if (($rotateSize = $input->getOption('rotate-size')) !== null) { + $rotateSize = \OCP\Util::computerFileSize($rotateSize); + $this->validateRotateSize($rotateSize); + $toBeSet['log_rotate_size'] = $rotateSize; + } + + // set config + foreach ($toBeSet as $option => $value) { + $this->config->setSystemValue($option, $value); + } + + // display config + // TODO: Drop backwards compatibility for config in the future + $logType = $this->config->getSystemValue('log_type', 'file'); + if ($logType === 'file' || $logType === 'owncloud') { + $enabledText = 'enabled'; + } else { + $enabledText = 'disabled'; + } + $output->writeln('Log backend file: '.$enabledText); + + $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data'); + $defaultLogFile = rtrim($dataDir, '/').'/nextcloud.log'; + $output->writeln('Log file: '.$this->config->getSystemValue('logfile', $defaultLogFile)); + + $rotateSize = $this->config->getSystemValue('log_rotate_size', 0); + if ($rotateSize) { + $rotateString = \OCP\Util::humanFileSize($rotateSize); + } else { + $rotateString = 'disabled'; + } + $output->writeln('Rotate at: '.$rotateString); + } + + /** + * @param mixed $rotateSize + * @throws \InvalidArgumentException + */ + protected function validateRotateSize(&$rotateSize) { + if ($rotateSize === false) { + throw new \InvalidArgumentException('Error parsing log rotation file size'); + } + $rotateSize = (int) $rotateSize; + if ($rotateSize < 0) { + throw new \InvalidArgumentException('Log rotation file size must be non-negative'); + } + } + +} diff --git a/core/Command/Log/Manage.php b/core/Command/Log/Manage.php index 14d41170dca..554708dfa42 100644 --- a/core/Command/Log/Manage.php +++ b/core/Command/Log/Manage.php @@ -34,7 +34,7 @@ use Symfony\Component\Console\Output\OutputInterface; class Manage extends Command { - const DEFAULT_BACKEND = 'owncloud'; + const DEFAULT_BACKEND = 'file'; const DEFAULT_LOG_LEVEL = 2; const DEFAULT_TIMEZONE = 'UTC'; @@ -54,7 +54,7 @@ class Manage extends Command { 'backend', null, InputOption::VALUE_REQUIRED, - 'set the logging backend [owncloud, syslog, errorlog]' + 'set the logging backend [file, syslog, errorlog]' ) ->addOption( 'level', diff --git a/core/Command/Log/OwnCloud.php b/core/Command/Log/OwnCloud.php deleted file mode 100644 index 391259f76b8..00000000000 --- a/core/Command/Log/OwnCloud.php +++ /dev/null @@ -1,126 +0,0 @@ - - * @author Thomas Pulzer - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -namespace OC\Core\Command\Log; - -use \OCP\IConfig; - -use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Output\OutputInterface; - -class OwnCloud extends Command { - - /** @var IConfig */ - protected $config; - - public function __construct(IConfig $config) { - $this->config = $config; - parent::__construct(); - } - - protected function configure() { - $this - ->setName('log:owncloud') - ->setDescription('manipulate ownCloud logging backend') - ->addOption( - 'enable', - null, - InputOption::VALUE_NONE, - 'enable this logging backend' - ) - ->addOption( - 'file', - null, - InputOption::VALUE_REQUIRED, - 'set the log file path' - ) - ->addOption( - 'rotate-size', - null, - InputOption::VALUE_REQUIRED, - 'set the file size for log rotation, 0 = disabled' - ) - ; - } - - protected function execute(InputInterface $input, OutputInterface $output) { - $toBeSet = []; - - if ($input->getOption('enable')) { - $toBeSet['log_type'] = 'owncloud'; - } - - if ($file = $input->getOption('file')) { - $toBeSet['logfile'] = $file; - } - - if (($rotateSize = $input->getOption('rotate-size')) !== null) { - $rotateSize = \OCP\Util::computerFileSize($rotateSize); - $this->validateRotateSize($rotateSize); - $toBeSet['log_rotate_size'] = $rotateSize; - } - - // set config - foreach ($toBeSet as $option => $value) { - $this->config->setSystemValue($option, $value); - } - - // display config - if ($this->config->getSystemValue('log_type', 'owncloud') === 'owncloud') { - $enabledText = 'enabled'; - } else { - $enabledText = 'disabled'; - } - $output->writeln('Log backend ownCloud: '.$enabledText); - - $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data'); - $defaultLogFile = rtrim($dataDir, '/').'/nextcloud.log'; - $output->writeln('Log file: '.$this->config->getSystemValue('logfile', $defaultLogFile)); - - $rotateSize = $this->config->getSystemValue('log_rotate_size', 0); - if ($rotateSize) { - $rotateString = \OCP\Util::humanFileSize($rotateSize); - } else { - $rotateString = 'disabled'; - } - $output->writeln('Rotate at: '.$rotateString); - } - - /** - * @param mixed $rotateSize - * @throws \InvalidArgumentException - */ - protected function validateRotateSize(&$rotateSize) { - if ($rotateSize === false) { - throw new \InvalidArgumentException('Error parsing log rotation file size'); - } - $rotateSize = (int) $rotateSize; - if ($rotateSize < 0) { - throw new \InvalidArgumentException('Log rotation file size must be non-negative'); - } - } - -} -- cgit v1.2.3