diff options
author | Robin Appelman <robin@icewind.nl> | 2023-05-26 18:57:42 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2023-07-10 18:29:09 +0200 |
commit | 7d17d2517f616e78ebceba703c1dc3ca8d63e2ed (patch) | |
tree | ca93f8c03e83780a83bb59c35011474f7637ce4f /lib/private/Log.php | |
parent | 1b422df12ac8eb26514849fb117e0dcf58623b88 (diff) | |
download | nextcloud-server-7d17d2517f616e78ebceba703c1dc3ca8d63e2ed.tar.gz nextcloud-server-7d17d2517f616e78ebceba703c1dc3ca8d63e2ed.zip |
emit an event when a message is logged
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Log.php')
-rw-r--r-- | lib/private/Log.php | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/private/Log.php b/lib/private/Log.php index c139510a3b3..a83e652f8d3 100644 --- a/lib/private/Log.php +++ b/lib/private/Log.php @@ -39,6 +39,8 @@ namespace OC; use Exception; use Nextcloud\LogNormalizer\Normalizer; use OC\AppFramework\Bootstrap\Coordinator; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\Log\BeforeMessageLoggedEvent; use OCP\Log\IDataLogger; use Throwable; use function array_merge; @@ -64,6 +66,7 @@ class Log implements ILogger, IDataLogger { private ?bool $logConditionSatisfied = null; private ?Normalizer $normalizer; private ?IRegistry $crashReporters; + private ?IEventDispatcher $eventDispatcher; /** * @param IWriter $logger The logger that should be used @@ -71,7 +74,12 @@ class Log implements ILogger, IDataLogger { * @param Normalizer|null $normalizer * @param IRegistry|null $registry */ - public function __construct(IWriter $logger, SystemConfig $config = null, Normalizer $normalizer = null, IRegistry $registry = null) { + public function __construct( + IWriter $logger, + SystemConfig $config = null, + Normalizer $normalizer = null, + IRegistry $registry = null + ) { // FIXME: Add this for backwards compatibility, should be fixed at some point probably if ($config === null) { $config = \OC::$server->getSystemConfig(); @@ -85,6 +93,11 @@ class Log implements ILogger, IDataLogger { $this->normalizer = $normalizer; } $this->crashReporters = $registry; + $this->eventDispatcher = null; + } + + public function setEventDispatcher(IEventDispatcher $eventDispatcher) { + $this->eventDispatcher = $eventDispatcher; } /** @@ -203,6 +216,10 @@ class Log implements ILogger, IDataLogger { $app = $context['app'] ?? 'no app in context'; $entry = $this->interpolateMessage($context, $message); + if ($this->eventDispatcher) { + $this->eventDispatcher->dispatchTyped(new BeforeMessageLoggedEvent($app, $level, $entry)); + } + try { if ($level >= $minLevel) { $this->writeLog($app, $entry, $level); @@ -322,6 +339,10 @@ class Log implements ILogger, IDataLogger { array_walk($context, [$this->normalizer, 'format']); + if ($this->eventDispatcher) { + $this->eventDispatcher->dispatchTyped(new BeforeMessageLoggedEvent($app, $level, $data)); + } + try { if ($level >= $minLevel) { if (!$this->logger instanceof IFileBased) { |