Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions lib/Controller/LogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
Expand Down