diff options
author | Thomas Citharel <tcit@tcit.fr> | 2022-05-02 17:49:32 +0200 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2022-05-02 19:29:35 +0200 |
commit | 1e7d924c61f312364827af1014e765d98e71ac05 (patch) | |
tree | 1549d0fe92e7bba7dfb700b82797ac355bff7b7f /tests/lib/Log | |
parent | 3197ae83a4e85b1d26c8df7e5af04d50e89bd539 (diff) | |
download | nextcloud-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/Log')
-rw-r--r-- | tests/lib/Log/FileTest.php | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/tests/lib/Log/FileTest.php b/tests/lib/Log/FileTest.php index 937b3c75448..703c4280f24 100644 --- a/tests/lib/Log/FileTest.php +++ b/tests/lib/Log/FileTest.php @@ -1,6 +1,8 @@ <?php /** * + * @author Thomas Citharel <nextcloud@tcit.fr> + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE * License as published by the Free Software Foundation; either @@ -18,6 +20,7 @@ namespace Test\Log; use OC\Log\File; +use OCP\IConfig; use OCP\ILogger; use Test\TestCase; @@ -36,7 +39,7 @@ class FileTest extends TestCase { $config = \OC::$server->getSystemConfig(); $this->restore_logfile = $config->getValue("logfile"); $this->restore_logdateformat = $config->getValue('logdateformat'); - + $config->setValue("logfile", $config->getValue('datadirectory') . "/logtest.log"); $this->logFile = new File($config->getValue('datadirectory') . '/logtest.log', '', $config); } @@ -55,7 +58,28 @@ class FileTest extends TestCase { $this->logFile = new File($this->restore_logfile, '', $config); parent::tearDown(); } - + + public function testLogging() { + $config = \OC::$server->get(IConfig::class); + # delete old logfile + unlink($config->getSystemValue('logfile')); + + # set format & write log line + $config->setSystemValue('logdateformat', 'u'); + $this->logFile->write('code', ['something' => 'extra', 'message' => 'Testing logging'], ILogger::ERROR); + + # read log line + $handle = @fopen($config->getSystemValue('logfile'), 'r'); + $line = fread($handle, 1000); + fclose($handle); + + # check log has data content + $values = (array) json_decode($line, true); + $this->assertArrayNotHasKey('message', $values['data']); + $this->assertEquals('extra', $values['data']['something']); + $this->assertEquals('Testing logging', $values['message']); + } + public function testMicrosecondsLogTimestamp() { $config = \OC::$server->getConfig(); # delete old logfile @@ -69,7 +93,7 @@ class FileTest extends TestCase { $handle = @fopen($config->getSystemValue('logfile'), 'r'); $line = fread($handle, 1000); fclose($handle); - + # check timestamp has microseconds part $values = (array) json_decode($line); $microseconds = $values['time']; |