summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2018-09-06 09:18:10 +0200
committerGitHub <noreply@github.com>2018-09-06 09:18:10 +0200
commit5767f1c9d3e214bb8a20a838239220016cd54c58 (patch)
tree03572b7bdfe94fe3eda46c2a24654b2fcb709ea0
parentf778da90932c3d6bc370e0016bbc41a36035c653 (diff)
parent764c9122948d17d9b7ffc02959e6d3e63141b103 (diff)
downloadnextcloud-server-5767f1c9d3e214bb8a20a838239220016cd54c58.tar.gz
nextcloud-server-5767f1c9d3e214bb8a20a838239220016cd54c58.zip
Merge pull request #10973 from nextcloud/feature/crash-report-breadcrumbs
Add breadcrumb support to crash reporters
-rw-r--r--lib/composer/composer/autoload_classmap.php1
-rw-r--r--lib/composer/composer/autoload_static.php1
-rw-r--r--lib/private/Log.php4
-rw-r--r--lib/private/Support/CrashReport/Registry.php18
-rw-r--r--lib/public/Support/CrashReport/ICollectBreadcrumbs.php43
-rw-r--r--lib/public/Support/CrashReport/IRegistry.php11
-rw-r--r--tests/lib/Support/CrashReport/RegistryTest.php15
7 files changed, 93 insertions, 0 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 00d168f88fd..75a3c3d3cd6 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -328,6 +328,7 @@ return array(
'OCP\\Share_Backend' => $baseDir . '/lib/public/Share_Backend.php',
'OCP\\Share_Backend_Collection' => $baseDir . '/lib/public/Share_Backend_Collection.php',
'OCP\\Share_Backend_File_Dependent' => $baseDir . '/lib/public/Share_Backend_File_Dependent.php',
+ 'OCP\\Support\\CrashReport\\ICollectBreadcrumbs' => $baseDir . '/lib/public/Support/CrashReport/ICollectBreadcrumbs.php',
'OCP\\Support\\CrashReport\\IRegistry' => $baseDir . '/lib/public/Support/CrashReport/IRegistry.php',
'OCP\\Support\\CrashReport\\IReporter' => $baseDir . '/lib/public/Support/CrashReport/IReporter.php',
'OCP\\SystemTag\\ISystemTag' => $baseDir . '/lib/public/SystemTag/ISystemTag.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index 7b0d042c85d..990bff668e4 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -358,6 +358,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\Share_Backend' => __DIR__ . '/../../..' . '/lib/public/Share_Backend.php',
'OCP\\Share_Backend_Collection' => __DIR__ . '/../../..' . '/lib/public/Share_Backend_Collection.php',
'OCP\\Share_Backend_File_Dependent' => __DIR__ . '/../../..' . '/lib/public/Share_Backend_File_Dependent.php',
+ 'OCP\\Support\\CrashReport\\ICollectBreadcrumbs' => __DIR__ . '/../../..' . '/lib/public/Support/CrashReport/ICollectBreadcrumbs.php',
'OCP\\Support\\CrashReport\\IRegistry' => __DIR__ . '/../../..' . '/lib/public/Support/CrashReport/IRegistry.php',
'OCP\\Support\\CrashReport\\IReporter' => __DIR__ . '/../../..' . '/lib/public/Support/CrashReport/IReporter.php',
'OCP\\SystemTag\\ISystemTag' => __DIR__ . '/../../..' . '/lib/public/SystemTag/ISystemTag.php',
diff --git a/lib/private/Log.php b/lib/private/Log.php
index 33d1ddcdc34..43ff4cc9dee 100644
--- a/lib/private/Log.php
+++ b/lib/private/Log.php
@@ -217,6 +217,10 @@ class Log implements ILogger {
if ($level >= $minLevel) {
$this->writeLog($app, $message, $level);
}
+
+ if (!is_null($this->crashReporters)) {
+ $this->crashReporters->delegateBreadcrumb($message, 'log', $context);
+ }
}
private function getLogLevel($context) {
diff --git a/lib/private/Support/CrashReport/Registry.php b/lib/private/Support/CrashReport/Registry.php
index 5eb78965c19..72c43fe37e2 100644
--- a/lib/private/Support/CrashReport/Registry.php
+++ b/lib/private/Support/CrashReport/Registry.php
@@ -23,6 +23,7 @@
namespace OC\Support\CrashReport;
use Exception;
+use OCP\Support\CrashReport\ICollectBreadcrumbs;
use OCP\Support\CrashReport\IRegistry;
use OCP\Support\CrashReport\IReporter;
use Throwable;
@@ -42,6 +43,23 @@ class Registry implements IRegistry {
}
/**
+ * Delegate breadcrumb collection to all registered reporters
+ *
+ * @param string $message
+ * @param string $category
+ * @param array $context
+ *
+ * @since 15.0.0
+ */
+ public function delegateBreadcrumb(string $message, string $category, array $context = []) {
+ foreach ($this->reporters as $reporter) {
+ if ($reporter instanceof ICollectBreadcrumbs) {
+ $reporter->collect($message, $category, $context);
+ }
+ }
+ }
+
+ /**
* Delegate crash reporting to all registered reporters
*
* @param Exception|Throwable $exception
diff --git a/lib/public/Support/CrashReport/ICollectBreadcrumbs.php b/lib/public/Support/CrashReport/ICollectBreadcrumbs.php
new file mode 100644
index 00000000000..6f331077f1a
--- /dev/null
+++ b/lib/public/Support/CrashReport/ICollectBreadcrumbs.php
@@ -0,0 +1,43 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @author Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCP\Support\CrashReport;
+
+/**
+ * @since 15.0.0
+ */
+interface ICollectBreadcrumbs extends IReporter {
+
+ /**
+ * Collect breadcrumbs for crash reports
+ *
+ * @param string $message
+ * @param string $category
+ * @param array $context
+ *
+ * @since 15.0.0
+ */
+ public function collect(string $message, string $category, array $context = []);
+
+}
diff --git a/lib/public/Support/CrashReport/IRegistry.php b/lib/public/Support/CrashReport/IRegistry.php
index 62432c782ab..2833e66a9b7 100644
--- a/lib/public/Support/CrashReport/IRegistry.php
+++ b/lib/public/Support/CrashReport/IRegistry.php
@@ -39,6 +39,17 @@ interface IRegistry {
public function register(IReporter $reporter);
/**
+ * Delegate breadcrumb collection to all registered reporters
+ *
+ * @param string $message
+ * @param string $category
+ * @param array $context
+ *
+ * @since 15.0.0
+ */
+ public function delegateBreadcrumb(string $message, string $category, array $context = []);
+
+ /**
* Delegate crash reporting to all registered reporters
*
* @since 13.0.0
diff --git a/tests/lib/Support/CrashReport/RegistryTest.php b/tests/lib/Support/CrashReport/RegistryTest.php
index ba225ec1330..5cb15db7345 100644
--- a/tests/lib/Support/CrashReport/RegistryTest.php
+++ b/tests/lib/Support/CrashReport/RegistryTest.php
@@ -26,6 +26,7 @@ namespace Test\Support\CrashReport;
use Exception;
use OC\Support\CrashReport\Registry;
+use OCP\Support\CrashReport\ICollectBreadcrumbs;
use OCP\Support\CrashReport\IReporter;
use Test\TestCase;
@@ -50,6 +51,20 @@ class RegistryTest extends TestCase {
$this->addToAssertionCount(1);
}
+ public function testDelegateBreadcrumbCollection() {
+ $reporter1 = $this->createMock(IReporter::class);
+ $reporter2 = $this->createMock(ICollectBreadcrumbs::class);
+ $message = 'hello';
+ $category = 'log';
+ $reporter2->expects($this->once())
+ ->method('collect')
+ ->with($message, $category);
+
+ $this->registry->register($reporter1);
+ $this->registry->register($reporter2);
+ $this->registry->delegateBreadcrumb($message, $category);
+ }
+
public function testDelegateToAll() {
$reporter1 = $this->createMock(IReporter::class);
$reporter2 = $this->createMock(IReporter::class);