Add breadcrumb support to crash reporters
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
parent
0899f2cbc4
commit
ff58732c0d
|
@ -217,6 +217,10 @@ class Log implements ILogger {
|
||||||
if ($level >= $minLevel) {
|
if ($level >= $minLevel) {
|
||||||
$this->writeLog($app, $message, $level);
|
$this->writeLog($app, $message, $level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!is_null($this->crashReporters)) {
|
||||||
|
$this->crashReporters->delegateBreadcrumb($message, 'log', $context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getLogLevel($context) {
|
private function getLogLevel($context) {
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
namespace OC\Support\CrashReport;
|
namespace OC\Support\CrashReport;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use OCP\Support\CrashReport\ICollectBreadcrumbs;
|
||||||
use OCP\Support\CrashReport\IRegistry;
|
use OCP\Support\CrashReport\IRegistry;
|
||||||
use OCP\Support\CrashReport\IReporter;
|
use OCP\Support\CrashReport\IReporter;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
@ -41,6 +42,23 @@ class Registry implements IRegistry {
|
||||||
$this->reporters[] = $reporter;
|
$this->reporters[] = $reporter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delegate breadcrumb collection to all registered reporters
|
||||||
|
*
|
||||||
|
* @param string $message
|
||||||
|
* @param string $category
|
||||||
|
* @param array $context
|
||||||
|
*
|
||||||
|
* @since 13.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
|
* Delegate crash reporting to all registered reporters
|
||||||
*
|
*
|
||||||
|
|
|
@ -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 = []);
|
||||||
|
|
||||||
|
}
|
|
@ -38,6 +38,17 @@ interface IRegistry {
|
||||||
*/
|
*/
|
||||||
public function register(IReporter $reporter);
|
public function register(IReporter $reporter);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delegate breadcrumb collection to all registered reporters
|
||||||
|
*
|
||||||
|
* @param string $message
|
||||||
|
* @param string $category
|
||||||
|
* @param array $context
|
||||||
|
*
|
||||||
|
* @since 13.0.0
|
||||||
|
*/
|
||||||
|
public function delegateBreadcrumb(string $message, string $category, array $context = []);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delegate crash reporting to all registered reporters
|
* Delegate crash reporting to all registered reporters
|
||||||
*
|
*
|
||||||
|
|
|
@ -26,6 +26,7 @@ namespace Test\Support\CrashReport;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use OC\Support\CrashReport\Registry;
|
use OC\Support\CrashReport\Registry;
|
||||||
|
use OCP\Support\CrashReport\ICollectBreadcrumbs;
|
||||||
use OCP\Support\CrashReport\IReporter;
|
use OCP\Support\CrashReport\IReporter;
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
|
||||||
|
@ -50,6 +51,20 @@ class RegistryTest extends TestCase {
|
||||||
$this->addToAssertionCount(1);
|
$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() {
|
public function testDelegateToAll() {
|
||||||
$reporter1 = $this->createMock(IReporter::class);
|
$reporter1 = $this->createMock(IReporter::class);
|
||||||
$reporter2 = $this->createMock(IReporter::class);
|
$reporter2 = $this->createMock(IReporter::class);
|
||||||
|
|
Loading…
Reference in New Issue