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. --- config/config.sample.php | 2 +- core/Command/Log/File.php | 128 ++++++++++++++++++ core/Command/Log/Manage.php | 4 +- core/Command/Log/OwnCloud.php | 126 ------------------ core/register_command.php | 2 +- lib/private/Log.php | 4 +- lib/private/Log/File.php | 185 ++++++++++++++++++++++++++ lib/private/Log/Owncloud.php | 185 -------------------------- lib/private/Log/Syslog.php | 2 +- lib/private/Server.php | 5 +- settings/Controller/LogSettingsController.php | 6 +- settings/admin.php | 7 +- tests/Core/Command/Log/ManageTest.php | 2 +- tests/Core/Command/Log/OwnCloudTest.php | 10 +- tests/lib/Log/OwncloudTest.php | 8 +- 15 files changed, 341 insertions(+), 335 deletions(-) create mode 100644 core/Command/Log/File.php delete mode 100644 core/Command/Log/OwnCloud.php create mode 100644 lib/private/Log/File.php delete mode 100644 lib/private/Log/Owncloud.php diff --git a/config/config.sample.php b/config/config.sample.php index 3376603373a..0b1aeeabf21 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -569,7 +569,7 @@ $CONFIG = array( * Setting this parameter to ``errorlog`` will use the PHP error_log function * for logging. */ -'log_type' => 'owncloud', +'log_type' => 'file', /** * Log file path for the Nextcloud logging type. 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'); - } - } - -} diff --git a/core/register_command.php b/core/register_command.php index 6f20769fa70..6a220c22b3f 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -99,7 +99,7 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) { ); $application->add(new OC\Core\Command\Log\Manage(\OC::$server->getConfig())); - $application->add(new OC\Core\Command\Log\OwnCloud(\OC::$server->getConfig())); + $application->add(new OC\Core\Command\Log\File(\OC::$server->getConfig())); $view = new \OC\Files\View(); $util = new \OC\Encryption\Util( diff --git a/lib/private/Log.php b/lib/private/Log.php index 59233cf5c12..2d06e62f54c 100644 --- a/lib/private/Log.php +++ b/lib/private/Log.php @@ -103,7 +103,9 @@ class Log implements ILogger { // FIXME: Add this for backwards compatibility, should be fixed at some point probably if($logger === null) { - $this->logger = 'OC\\Log\\'.ucfirst($this->config->getValue('log_type', 'owncloud')); + // TODO: Drop backwards compatibility for config in the future + $logType = $this->config->getValue('log_type', 'file'); + $this->logger = 'OC\\Log\\'.ucfirst($logType=='owncloud' ? 'file' : $logType); call_user_func(array($this->logger, 'init')); } else { $this->logger = $logger; diff --git a/lib/private/Log/File.php b/lib/private/Log/File.php new file mode 100644 index 00000000000..a406dd83952 --- /dev/null +++ b/lib/private/Log/File.php @@ -0,0 +1,185 @@ + + * @author Bart Visscher + * @author Georg Ehrke + * @author Lukas Reschke + * @author Michael Gapczynski + * @author Morris Jobke + * @author Phiber2000 + * @author Robin Appelman + * @author Roeland Jago Douma + * @author Thomas Müller + * @author Thomas Pulzer + * @author Vincent Petry + * + * @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\Log; + +/** + * logging utilities + * + * Log is saved at data/nextcloud.log (on default) + */ + +class File { + static protected $logFile; + + /** + * Init class data + */ + public static function init() { + $systemConfig = \OC::$server->getSystemConfig(); + $defaultLogFile = $systemConfig->getValue("datadirectory", \OC::$SERVERROOT.'/data').'/nextcloud.log'; + self::$logFile = $systemConfig->getValue("logfile", $defaultLogFile); + + /** + * Fall back to default log file if specified logfile does not exist + * and can not be created. + */ + if (!file_exists(self::$logFile)) { + if(!is_writable(dirname(self::$logFile))) { + self::$logFile = $defaultLogFile; + } else { + if(!touch(self::$logFile)) { + self::$logFile = $defaultLogFile; + } + } + } + } + + /** + * write a message in the log + * @param string $app + * @param string $message + * @param int $level + */ + public static function write($app, $message, $level) { + $config = \OC::$server->getSystemConfig(); + + // default to ISO8601 + $format = $config->getValue('logdateformat', 'c'); + $logTimeZone = $config->getValue( "logtimezone", 'UTC' ); + try { + $timezone = new \DateTimeZone($logTimeZone); + } catch (\Exception $e) { + $timezone = new \DateTimeZone('UTC'); + } + $time = \DateTime::createFromFormat("U.u", number_format(microtime(true), 4, ".", "")); + if ($time === false) { + $time = new \DateTime(null, $timezone); + } else { + // apply timezone if $time is created from UNIX timestamp + $time->setTimezone($timezone); + } + $request = \OC::$server->getRequest(); + $reqId = $request->getId(); + $remoteAddr = $request->getRemoteAddress(); + // remove username/passwords from URLs before writing the to the log file + $time = $time->format($format); + $url = ($request->getRequestUri() !== '') ? $request->getRequestUri() : '--'; + $method = is_string($request->getMethod()) ? $request->getMethod() : '--'; + if(\OC::$server->getConfig()->getSystemValue('installed', false)) { + $user = (\OC_User::getUser()) ? \OC_User::getUser() : '--'; + } else { + $user = '--'; + } + $entry = compact( + 'reqId', + 'remoteAddr', + 'app', + 'message', + 'level', + 'time', + 'method', + 'url', + 'user' + ); + $entry = json_encode($entry); + $handle = @fopen(self::$logFile, 'a'); + @chmod(self::$logFile, 0640); + if ($handle) { + fwrite($handle, $entry."\n"); + fclose($handle); + } else { + // Fall back to error_log + error_log($entry); + } + if (php_sapi_name() === 'cli-server') { + error_log($message, 4); + } + } + + /** + * get entries from the log in reverse chronological order + * @param int $limit + * @param int $offset + * @return array + */ + public static function getEntries($limit=50, $offset=0) { + self::init(); + $minLevel = \OC::$server->getSystemConfig()->getValue("loglevel", \OCP\Util::WARN); + $entries = array(); + $handle = @fopen(self::$logFile, 'rb'); + if ($handle) { + fseek($handle, 0, SEEK_END); + $pos = ftell($handle); + $line = ''; + $entriesCount = 0; + $lines = 0; + // Loop through each character of the file looking for new lines + while ($pos >= 0 && ($limit === null ||$entriesCount < $limit)) { + fseek($handle, $pos); + $ch = fgetc($handle); + if ($ch == "\n" || $pos == 0) { + if ($line != '') { + // Add the first character if at the start of the file, + // because it doesn't hit the else in the loop + if ($pos == 0) { + $line = $ch.$line; + } + $entry = json_decode($line); + // Add the line as an entry if it is passed the offset and is equal or above the log level + if ($entry->level >= $minLevel) { + $lines++; + if ($lines > $offset) { + $entries[] = $entry; + $entriesCount++; + } + } + $line = ''; + } + } else { + $line = $ch.$line; + } + $pos--; + } + fclose($handle); + } + return $entries; + } + + /** + * @return string + */ + public static function getLogFilePath() { + return self::$logFile; + } +} diff --git a/lib/private/Log/Owncloud.php b/lib/private/Log/Owncloud.php deleted file mode 100644 index 2cc70015e3c..00000000000 --- a/lib/private/Log/Owncloud.php +++ /dev/null @@ -1,185 +0,0 @@ - - * @author Bart Visscher - * @author Georg Ehrke - * @author Lukas Reschke - * @author Michael Gapczynski - * @author Morris Jobke - * @author Phiber2000 - * @author Robin Appelman - * @author Roeland Jago Douma - * @author Thomas Müller - * @author Thomas Pulzer - * @author Vincent Petry - * - * @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\Log; - -/** - * logging utilities - * - * Log is saved at data/nextcloud.log (on default) - */ - -class Owncloud { - static protected $logFile; - - /** - * Init class data - */ - public static function init() { - $systemConfig = \OC::$server->getSystemConfig(); - $defaultLogFile = $systemConfig->getValue("datadirectory", \OC::$SERVERROOT.'/data').'/nextcloud.log'; - self::$logFile = $systemConfig->getValue("logfile", $defaultLogFile); - - /** - * Fall back to default log file if specified logfile does not exist - * and can not be created. - */ - if (!file_exists(self::$logFile)) { - if(!is_writable(dirname(self::$logFile))) { - self::$logFile = $defaultLogFile; - } else { - if(!touch(self::$logFile)) { - self::$logFile = $defaultLogFile; - } - } - } - } - - /** - * write a message in the log - * @param string $app - * @param string $message - * @param int $level - */ - public static function write($app, $message, $level) { - $config = \OC::$server->getSystemConfig(); - - // default to ISO8601 - $format = $config->getValue('logdateformat', 'c'); - $logTimeZone = $config->getValue( "logtimezone", 'UTC' ); - try { - $timezone = new \DateTimeZone($logTimeZone); - } catch (\Exception $e) { - $timezone = new \DateTimeZone('UTC'); - } - $time = \DateTime::createFromFormat("U.u", number_format(microtime(true), 4, ".", "")); - if ($time === false) { - $time = new \DateTime(null, $timezone); - } else { - // apply timezone if $time is created from UNIX timestamp - $time->setTimezone($timezone); - } - $request = \OC::$server->getRequest(); - $reqId = $request->getId(); - $remoteAddr = $request->getRemoteAddress(); - // remove username/passwords from URLs before writing the to the log file - $time = $time->format($format); - $url = ($request->getRequestUri() !== '') ? $request->getRequestUri() : '--'; - $method = is_string($request->getMethod()) ? $request->getMethod() : '--'; - if(\OC::$server->getConfig()->getSystemValue('installed', false)) { - $user = (\OC_User::getUser()) ? \OC_User::getUser() : '--'; - } else { - $user = '--'; - } - $entry = compact( - 'reqId', - 'remoteAddr', - 'app', - 'message', - 'level', - 'time', - 'method', - 'url', - 'user' - ); - $entry = json_encode($entry); - $handle = @fopen(self::$logFile, 'a'); - @chmod(self::$logFile, 0640); - if ($handle) { - fwrite($handle, $entry."\n"); - fclose($handle); - } else { - // Fall back to error_log - error_log($entry); - } - if (php_sapi_name() === 'cli-server') { - error_log($message, 4); - } - } - - /** - * get entries from the log in reverse chronological order - * @param int $limit - * @param int $offset - * @return array - */ - public static function getEntries($limit=50, $offset=0) { - self::init(); - $minLevel = \OC::$server->getSystemConfig()->getValue("loglevel", \OCP\Util::WARN); - $entries = array(); - $handle = @fopen(self::$logFile, 'rb'); - if ($handle) { - fseek($handle, 0, SEEK_END); - $pos = ftell($handle); - $line = ''; - $entriesCount = 0; - $lines = 0; - // Loop through each character of the file looking for new lines - while ($pos >= 0 && ($limit === null ||$entriesCount < $limit)) { - fseek($handle, $pos); - $ch = fgetc($handle); - if ($ch == "\n" || $pos == 0) { - if ($line != '') { - // Add the first character if at the start of the file, - // because it doesn't hit the else in the loop - if ($pos == 0) { - $line = $ch.$line; - } - $entry = json_decode($line); - // Add the line as an entry if it is passed the offset and is equal or above the log level - if ($entry->level >= $minLevel) { - $lines++; - if ($lines > $offset) { - $entries[] = $entry; - $entriesCount++; - } - } - $line = ''; - } - } else { - $line = $ch.$line; - } - $pos--; - } - fclose($handle); - } - return $entries; - } - - /** - * @return string - */ - public static function getLogFilePath() { - return self::$logFile; - } -} diff --git a/lib/private/Log/Syslog.php b/lib/private/Log/Syslog.php index c6ea0a40350..73978250310 100644 --- a/lib/private/Log/Syslog.php +++ b/lib/private/Log/Syslog.php @@ -38,7 +38,7 @@ class Syslog { * Init class data */ public static function init() { - openlog(\OC::$server->getSystemConfig()->getValue("syslog_tag", "ownCloud"), LOG_PID | LOG_CONS, LOG_USER); + openlog(\OC::$server->getSystemConfig()->getValue("syslog_tag", "Nextcloud"), LOG_PID | LOG_CONS, LOG_USER); // Close at shutdown register_shutdown_function('closelog'); } diff --git a/lib/private/Server.php b/lib/private/Server.php index de2970d9bfa..bc1e526786d 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -364,8 +364,9 @@ class Server extends ServerContainer implements IServerContainer { ); }); $this->registerService('Logger', function (Server $c) { - $logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud'); - $logger = 'OC\\Log\\' . ucfirst($logClass); + $logClass = $c->query('AllConfig')->getSystemValue('log_type', 'file'); + // TODO: Drop backwards compatibility for config in the future + $logger = 'OC\\Log\\' . ucfirst($logClass=='owncloud' ? 'file' : $logClass); call_user_func(array($logger, 'init')); return new Log($logger); diff --git a/settings/Controller/LogSettingsController.php b/settings/Controller/LogSettingsController.php index ce4913c2478..23e0fba902a 100644 --- a/settings/Controller/LogSettingsController.php +++ b/settings/Controller/LogSettingsController.php @@ -93,8 +93,8 @@ class LogSettingsController extends Controller { */ public function getEntries($count=50, $offset=0) { return new JSONResponse([ - 'data' => \OC\Log\Owncloud::getEntries($count, $offset), - 'remain' => count(\OC\Log\Owncloud::getEntries(1, $offset + $count)) !== 0, + 'data' => \OC\Log\File::getEntries($count, $offset), + 'remain' => count(\OC\Log\File::getEntries(1, $offset + $count)) !== 0, ]); } @@ -106,7 +106,7 @@ class LogSettingsController extends Controller { * @return StreamResponse */ public function download() { - $resp = new StreamResponse(\OC\Log\Owncloud::getLogFilePath()); + $resp = new StreamResponse(\OC\Log\File::getLogFilePath()); $resp->addHeader('Content-Type', 'application/octet-stream'); $resp->addHeader('Content-Disposition', 'attachment; filename="nextcloud.log"'); return $resp; diff --git a/settings/admin.php b/settings/admin.php index 11d3a3f40db..a458c813c11 100644 --- a/settings/admin.php +++ b/settings/admin.php @@ -44,12 +44,13 @@ OC_Util::addScript('files', 'jquery.fileupload'); \OC::$server->getEventDispatcher()->dispatch('OC\Settings\Admin::loadAdditionalScripts'); -$showLog = (\OC::$server->getConfig()->getSystemValue('log_type', 'owncloud') === 'owncloud'); +$logType = \OC::$server->getConfig()->getSystemValue('log_type', 'file'); +$showLog = ($logType === 'file' || $logType === 'owncloud'); $numEntriesToLoad = 3; -$entries = \OC\Log\Owncloud::getEntries($numEntriesToLoad + 1); +$entries = \OC\Log\File::getEntries($numEntriesToLoad + 1); $entriesRemaining = count($entries) > $numEntriesToLoad; $entries = array_slice($entries, 0, $numEntriesToLoad); -$logFilePath = \OC\Log\Owncloud::getLogFilePath(); +$logFilePath = \OC\Log\File::getLogFilePath(); $doesLogFileExist = file_exists($logFilePath); $logFileSize = 0; if($doesLogFileExist) { diff --git a/tests/Core/Command/Log/ManageTest.php b/tests/Core/Command/Log/ManageTest.php index 6fb83347f23..cf4506a64eb 100644 --- a/tests/Core/Command/Log/ManageTest.php +++ b/tests/Core/Command/Log/ManageTest.php @@ -154,7 +154,7 @@ class ManageTest extends TestCase { public function testGetConfiguration() { $this->config->expects($this->at(0)) ->method('getSystemValue') - ->with('log_type', 'owncloud') + ->with('log_type', 'file') ->willReturn('log_type_value'); $this->config->expects($this->at(1)) ->method('getSystemValue') diff --git a/tests/Core/Command/Log/OwnCloudTest.php b/tests/Core/Command/Log/OwnCloudTest.php index e0445a5cfda..8f217cce653 100644 --- a/tests/Core/Command/Log/OwnCloudTest.php +++ b/tests/Core/Command/Log/OwnCloudTest.php @@ -22,7 +22,7 @@ namespace Tests\Core\Command\Log; -use OC\Core\Command\Log\OwnCloud; +use OC\Core\Command\Log\File; use Test\TestCase; class OwnCloudTest extends TestCase { @@ -45,7 +45,7 @@ class OwnCloudTest extends TestCase { $this->consoleInput = $this->getMock('Symfony\Component\Console\Input\InputInterface'); $this->consoleOutput = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); - $this->command = new OwnCloud($config); + $this->command = new File($config); } public function testEnable() { @@ -55,7 +55,7 @@ class OwnCloudTest extends TestCase { ])); $this->config->expects($this->once()) ->method('setSystemValue') - ->with('log_type', 'owncloud'); + ->with('log_type', 'file'); self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]); } @@ -99,7 +99,7 @@ class OwnCloudTest extends TestCase { public function testGetConfiguration() { $this->config->method('getSystemValue') ->will($this->returnValueMap([ - ['log_type', 'owncloud', 'log_type_value'], + ['log_type', 'file', 'log_type_value'], ['datadirectory', \OC::$SERVERROOT.'/data', '/data/directory/'], ['logfile', '/data/directory/nextcloud.log', '/var/log/nextcloud.log'], ['log_rotate_size', 0, 5 * 1024 * 1024], @@ -107,7 +107,7 @@ class OwnCloudTest extends TestCase { $this->consoleOutput->expects($this->at(0)) ->method('writeln') - ->with('Log backend ownCloud: disabled'); + ->with('Log backend file: disabled'); $this->consoleOutput->expects($this->at(1)) ->method('writeln') ->with('Log file: /var/log/nextcloud.log'); diff --git a/tests/lib/Log/OwncloudTest.php b/tests/lib/Log/OwncloudTest.php index e19063a83f5..3835048fe54 100644 --- a/tests/lib/Log/OwncloudTest.php +++ b/tests/lib/Log/OwncloudTest.php @@ -17,7 +17,7 @@ namespace Test\Log; -use OC\Log\Owncloud; +use OC\Log\File; use Test\TestCase; /** @@ -37,7 +37,7 @@ class OwncloudTest extends TestCase $this->restore_logdateformat = $config->getSystemValue('logdateformat'); $config->setSystemValue("logfile", $config->getSystemValue('datadirectory') . "/logtest"); - Owncloud::init(); + File::init(); } protected function tearDown() { $config = \OC::$server->getConfig(); @@ -51,7 +51,7 @@ class OwncloudTest extends TestCase } else { $config->deleteSystemValue("restore_logdateformat"); } - Owncloud::init(); + File::init(); parent::tearDown(); } @@ -62,7 +62,7 @@ class OwncloudTest extends TestCase # set format & write log line $config->setSystemValue('logdateformat', 'u'); - Owncloud::write('test', 'message', \OCP\Util::ERROR); + File::write('test', 'message', \OCP\Util::ERROR); # read log line $handle = @fopen($config->getSystemValue('logfile'), 'r'); -- cgit v1.2.3