Use PSR Logger in event dispatcher
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
e10cad4a71
commit
51fbcb0801
|
@ -35,6 +35,7 @@ use OCP\ILogger;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
use OCP\IUserSession;
|
use OCP\IUserSession;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
|
|
||||||
class RootCollectionTest extends \Test\TestCase {
|
class RootCollectionTest extends \Test\TestCase {
|
||||||
|
@ -77,7 +78,7 @@ class RootCollectionTest extends \Test\TestCase {
|
||||||
new EventDispatcher(
|
new EventDispatcher(
|
||||||
new \Symfony\Component\EventDispatcher\EventDispatcher(),
|
new \Symfony\Component\EventDispatcher\EventDispatcher(),
|
||||||
\OC::$server,
|
\OC::$server,
|
||||||
$this->logger
|
$this->createMock(LoggerInterface::class)
|
||||||
),
|
),
|
||||||
$this->logger
|
$this->logger
|
||||||
);
|
);
|
||||||
|
|
|
@ -28,6 +28,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace OC\EventDispatcher;
|
namespace OC\EventDispatcher;
|
||||||
|
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use function get_class;
|
use function get_class;
|
||||||
use OC\Broadcast\Events\BroadcastEvent;
|
use OC\Broadcast\Events\BroadcastEvent;
|
||||||
use OCP\Broadcast\Events\IBroadcastEvent;
|
use OCP\Broadcast\Events\IBroadcastEvent;
|
||||||
|
@ -35,7 +36,6 @@ use OCP\EventDispatcher\ABroadcastedEvent;
|
||||||
use OCP\EventDispatcher\Event;
|
use OCP\EventDispatcher\Event;
|
||||||
use OCP\EventDispatcher\IEventDispatcher;
|
use OCP\EventDispatcher\IEventDispatcher;
|
||||||
use OCP\IContainer;
|
use OCP\IContainer;
|
||||||
use OCP\ILogger;
|
|
||||||
use OCP\IServerContainer;
|
use OCP\IServerContainer;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcher as SymfonyDispatcher;
|
use Symfony\Component\EventDispatcher\EventDispatcher as SymfonyDispatcher;
|
||||||
|
|
||||||
|
@ -47,12 +47,12 @@ class EventDispatcher implements IEventDispatcher {
|
||||||
/** @var IContainer */
|
/** @var IContainer */
|
||||||
private $container;
|
private $container;
|
||||||
|
|
||||||
/** @var ILogger */
|
/** @var LoggerInterface */
|
||||||
private $logger;
|
private $logger;
|
||||||
|
|
||||||
public function __construct(SymfonyDispatcher $dispatcher,
|
public function __construct(SymfonyDispatcher $dispatcher,
|
||||||
IServerContainer $container,
|
IServerContainer $container,
|
||||||
ILogger $logger) {
|
LoggerInterface $logger) {
|
||||||
$this->dispatcher = $dispatcher;
|
$this->dispatcher = $dispatcher;
|
||||||
$this->container = $container;
|
$this->container = $container;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
|
|
|
@ -30,7 +30,7 @@ use OCP\AppFramework\QueryException;
|
||||||
use OCP\EventDispatcher\Event;
|
use OCP\EventDispatcher\Event;
|
||||||
use OCP\EventDispatcher\IEventListener;
|
use OCP\EventDispatcher\IEventListener;
|
||||||
use OCP\IContainer;
|
use OCP\IContainer;
|
||||||
use OCP\ILogger;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lazy service event listener
|
* Lazy service event listener
|
||||||
|
@ -46,7 +46,7 @@ final class ServiceEventListener {
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $class;
|
private $class;
|
||||||
|
|
||||||
/** @var ILogger */
|
/** @var LoggerInterface */
|
||||||
private $logger;
|
private $logger;
|
||||||
|
|
||||||
/** @var null|IEventListener */
|
/** @var null|IEventListener */
|
||||||
|
@ -54,7 +54,7 @@ final class ServiceEventListener {
|
||||||
|
|
||||||
public function __construct(IContainer $container,
|
public function __construct(IContainer $container,
|
||||||
string $class,
|
string $class,
|
||||||
ILogger $logger) {
|
LoggerInterface $logger) {
|
||||||
$this->container = $container;
|
$this->container = $container;
|
||||||
$this->class = $class;
|
$this->class = $class;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
|
@ -65,9 +65,8 @@ final class ServiceEventListener {
|
||||||
try {
|
try {
|
||||||
$this->service = $this->container->query($this->class);
|
$this->service = $this->container->query($this->class);
|
||||||
} catch (QueryException $e) {
|
} catch (QueryException $e) {
|
||||||
$this->logger->logException($e, [
|
$this->logger->error("Could not load event listener service " . $this->class, [
|
||||||
'level' => ILogger::ERROR,
|
'exception' => $e,
|
||||||
'message' => "Could not load event listener service " . $this->class,
|
|
||||||
]);
|
]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue