Skip to content

Commit

Permalink
Better handle when log_type isn't file and give explanation
Browse files Browse the repository at this point in the history
Fixes nextcloud#52 (and possibly others)

Currently if `log_type` is set to anything other than `file` (the default) - such as syslog or systemd - the Logging page spins indefinitely. This fixes the backend assumptions about logging always being log_type `file` and also provides the admin (user) with an informative message so they know what's going on.

Signed-off-by: Josh Richards <[email protected]>
  • Loading branch information
joshtrichards authored May 4, 2023
1 parent 827855f commit ad94c68
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions lib/Controller/LogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,30 @@ public function __construct($appName,
* @return TemplateResponse
*/
public function get($count = 50, $offset = 0, $levels = '11111') {
$iterator = $this->logIteratorFactory->getLogIterator($levels);
return $this->responseFromIterator($iterator, $count, $offset);
$logType = $this->config->getSystemValue('log_type','file');
if ($logType === 'file') { // we only support web access when `log_type` is set to `file` (the default)
$iterator = $this->logIteratorFactory->getLogIterator($levels);
return $this->responseFromIterator($iterator, $count, $offset);
} else { // A log_type other than `file` seems to be configured so:
// * Generate a dummy entry so we don't error out
// * Use the dummy entry to inform the admin to look elsewhere and/or correct their configuration
$dummyLine["id"] = uniqid();
$dummyLine["reqid"] = "00000000000000000000"; // irrelevant
$dummyLine["level"] = 1; // INFO
$dummyLine["time"] = date(DATE_ATOM, time());
$dummyLine["remoteAddr"] = "0.0.0.0";
$dummyLine["user"] = "---";
$dummyLine["app"] = "Logreader";
$dummyLine["method"] = "---";
$dummyLine["url"] = "---";
$dummyLine["message"] =
'File-based logging must be enabled to access logs from the Web UI. Your `log_type` is currently '
. 'set to: [' . $logType . ']. If you feel this is an error, please verify `log_type` in your '
. 'config.php and check the Nextcloud Administration Manual. This is not an actual log entry.';
$dummyLine["userAgent"] = "---";
$dummyLine["version"] = "---";
return new JSONResponse(['data' => $dummyLine, 'remain' => false]);
}
}


Expand Down Expand Up @@ -91,6 +113,12 @@ public function poll(string $lastReqId, string $levels = '11111'): JSONResponse
$cycles = 0;
$maxCycles = 20;

$logType = $this->config->getSystemValue('log_type','file');
if ($logType !== 'file') { // we only support access when `log_type` is set to `file` (the default)
// TODO: Don't even attempt polling in the front-end
sleep(20);
return new JSONResponse([]);
}
$lastItem = $this->getLastItem($levels);
while ($lastItem === null || $lastItem['reqId'] === $lastReqId) {
sleep(1);
Expand Down

0 comments on commit ad94c68

Please sign in to comment.