From bd38d77e9277aa5c61b6cd661bfddd339f119b4a Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 25 Apr 2018 12:41:45 +0200 Subject: [PATCH] adjust to changes from server/#9293 most old static classes are gone, and essentially there is just one standard log file (if in use). Signed-off-by: Arthur Schiwon --- lib/Controller/LogController.php | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/Controller/LogController.php b/lib/Controller/LogController.php index f0ab2fc77..c77cba765 100644 --- a/lib/Controller/LogController.php +++ b/lib/Controller/LogController.php @@ -28,6 +28,8 @@ use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\IRequest; +use OCP\Log\IFileBased; +use OCP\Log\ILogFactory; /** * Class LogController @@ -39,26 +41,33 @@ class LogController extends Controller { * @var IConfig */ private $config; + /** @var ILogFactory */ + private $logFactory; public function __construct($appName, IRequest $request, - IConfig $config) { + IConfig $config, + ILogFactory $logFactory + ) { parent::__construct($appName, $request); $this->config = $config; + $this->logFactory = $logFactory; } + /** + * @return LogIterator + * @throws \Exception + */ private function getLogIterator() { $dateFormat = $this->config->getSystemValue('logdateformat', \DateTime::ATOM); $timezone = $this->config->getSystemValue('logtimezone', 'UTC'); - $logClasses = ['\OC\Log\Owncloud', '\OC_Log_Owncloud', '\OC\Log\File']; - foreach ($logClasses as $logClass) { - if (class_exists($logClass)) { - $handle = fopen($logClass::getLogFilePath(), 'rb'); - if ($handle) { - return new LogIterator($handle, $dateFormat, $timezone); - } else { - throw new \Exception("Error while opening " . $logClass::getLogFilePath()); - } + $log = $this->logFactory->get('file'); + if($log instanceof IFileBased) { + $handle = fopen($log->getLogFilePath(), 'rb'); + if ($handle) { + return new LogIterator($handle, $dateFormat, $timezone); + } else { + throw new \Exception("Error while opening " . $log->getLogFilePath()); } } throw new \Exception('Can\'t find log class');