aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/lib/Controller/LogSettingsController.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/settings/lib/Controller/LogSettingsController.php')
-rw-r--r--apps/settings/lib/Controller/LogSettingsController.php50
1 files changed, 50 insertions, 0 deletions
diff --git a/apps/settings/lib/Controller/LogSettingsController.php b/apps/settings/lib/Controller/LogSettingsController.php
new file mode 100644
index 00000000000..90cf4549d2f
--- /dev/null
+++ b/apps/settings/lib/Controller/LogSettingsController.php
@@ -0,0 +1,50 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+namespace OCA\Settings\Controller;
+
+use OC\Log;
+use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http;
+use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
+use OCP\AppFramework\Http\Attribute\OpenAPI;
+use OCP\AppFramework\Http\StreamResponse;
+use OCP\IRequest;
+
+class LogSettingsController extends Controller {
+
+ /** @var Log */
+ private $log;
+
+ public function __construct(string $appName, IRequest $request, Log $logger) {
+ parent::__construct($appName, $request);
+ $this->log = $logger;
+ }
+
+ /**
+ * download logfile
+ *
+ * @return StreamResponse<Http::STATUS_OK, array{Content-Type: 'application/octet-stream', 'Content-Disposition': 'attachment; filename="nextcloud.log"'}>
+ *
+ * 200: Logfile returned
+ */
+ #[NoCSRFRequired]
+ #[OpenAPI(scope: OpenAPI::SCOPE_ADMINISTRATION)]
+ public function download() {
+ if (!$this->log instanceof Log) {
+ throw new \UnexpectedValueException('Log file not available');
+ }
+ return new StreamResponse(
+ $this->log->getLogPath(),
+ Http::STATUS_OK,
+ [
+ 'Content-Type' => 'application/octet-stream',
+ 'Content-Disposition' => 'attachment; filename="nextcloud.log"',
+ ],
+ );
+ }
+}