aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/LoggerTest.php
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2022-05-02 17:49:32 +0200
committerThomas Citharel <tcit@tcit.fr>2022-05-02 19:29:35 +0200
commit1e7d924c61f312364827af1014e765d98e71ac05 (patch)
tree1549d0fe92e7bba7dfb700b82797ac355bff7b7f /tests/lib/LoggerTest.php
parent3197ae83a4e85b1d26c8df7e5af04d50e89bd539 (diff)
downloadnextcloud-server-1e7d924c61f312364827af1014e765d98e71ac05.tar.gz
nextcloud-server-1e7d924c61f312364827af1014e765d98e71ac05.zip
Fix logging data context to file
It was only logged when an exception was provided or when using logData (which is not being much used). We make sure the interpolated parameters are not logged. Only tested with file write logger, but shouldn't work differently. Crash reporters always had the context. Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'tests/lib/LoggerTest.php')
-rw-r--r--tests/lib/LoggerTest.php33
1 files changed, 25 insertions, 8 deletions
diff --git a/tests/lib/LoggerTest.php b/tests/lib/LoggerTest.php
index 9b44fe198e2..bec2119a8ad 100644
--- a/tests/lib/LoggerTest.php
+++ b/tests/lib/LoggerTest.php
@@ -1,6 +1,9 @@
<?php
/**
* Copyright (c) 2014 Thomas Müller <thomas.mueller@tmit.eu>
+ *
+ * @author Thomas Citharel <nextcloud@tcit.fr>
+ *
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
@@ -9,29 +12,32 @@
namespace Test;
use OC\Log;
+use OC\SystemConfig;
use OCP\ILogger;
use OCP\Log\IWriter;
+use OCP\Support\CrashReport\IRegistry;
+use PHPUnit\Framework\MockObject\MockObject;
class LoggerTest extends TestCase implements IWriter {
- /** @var \OC\SystemConfig|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var SystemConfig|MockObject */
private $config;
- /** @var \OCP\Support\CrashReport\IRegistry|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IRegistry|MockObject */
private $registry;
- /** @var \OCP\ILogger */
+ /** @var ILogger */
private $logger;
/** @var array */
- private $logs = [];
+ private array $logs = [];
protected function setUp(): void {
parent::setUp();
$this->logs = [];
- $this->config = $this->createMock(\OC\SystemConfig::class);
- $this->registry = $this->createMock(\OCP\Support\CrashReport\IRegistry::class);
+ $this->config = $this->createMock(SystemConfig::class);
+ $this->registry = $this->createMock(IRegistry::class);
$this->logger = new Log($this, $this->config, null, $this->registry);
}
@@ -63,12 +69,23 @@ class LoggerTest extends TestCase implements IWriter {
$this->assertEquals($expected, $this->getLogs());
}
- private function getLogs() {
+ public function testLoggingWithDataArray(): void {
+ $writerMock = $this->createMock(IWriter::class);
+ $logFile = new Log($writerMock, $this->config);
+ $writerMock->expects($this->once())->method('write')->with('no app in context', ['something' => 'extra', 'message' => 'Testing logging with john']);
+ $logFile->error('Testing logging with {user}', ['something' => 'extra', 'user' => 'john']);
+ }
+
+ private function getLogs(): array {
return $this->logs;
}
public function write(string $app, $message, int $level) {
- $this->logs[] = "$level $message";
+ $textMessage = $message;
+ if (is_array($message)) {
+ $textMessage = $message['message'];
+ }
+ $this->logs[] = $level . " " . $textMessage;
}
public function userAndPasswordData(): array {