-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37454 from owncloud/fix-logger-writeExtra-37453
Fix logging when logger has no writeExtra method
- Loading branch information
Showing
3 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Bugfix: Logging of extra fields when logger does not have a writeExtra method | ||
|
||
If a logger in use does not have a writeExtra method then an error message would | ||
be generated when a log entry with extra data happens. | ||
|
||
This problem has been corrected. In this case the basic log information will be | ||
written without the extra data. | ||
|
||
https://github.com/owncloud/core/issues/37453 | ||
https://github.com/owncloud/core/pull/37454 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
/** | ||
* Copyright (c) 2020 Phil Davis <[email protected]> | ||
* This file is licensed under the Affero General Public License version 3 or | ||
* later. | ||
* See the COPYING-README file. | ||
*/ | ||
|
||
namespace Test; | ||
|
||
use OC\Log; | ||
use OCP\IConfig; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\EventDispatcher\EventDispatcher; | ||
|
||
class LoggerWithoutWriteExtraTest extends TestCase { | ||
/** @var \OCP\ILogger */ | ||
private $logger; | ||
private static $logs = []; | ||
|
||
/** @var IConfig | \PHPUnit\Framework\MockObject\MockObject */ | ||
private $config; | ||
|
||
protected function setUp(): void { | ||
parent::setUp(); | ||
|
||
self::$logs = []; | ||
$this->config = $this->getMockBuilder( | ||
'\OC\SystemConfig') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->logger = new Log( | ||
'Test\LoggerWithoutWriteExtraTest', | ||
$this->config, | ||
null, | ||
new EventDispatcher() | ||
); | ||
} | ||
|
||
private function getLogs() { | ||
return self::$logs; | ||
} | ||
|
||
public static function write($app, $message, $level) { | ||
self::$logs[]= "$level $message"; | ||
} | ||
|
||
public function testExtraFields() { | ||
$extraFields = [ | ||
'one' => 'un', | ||
'two' => 'deux', | ||
'three' => 'trois', | ||
]; | ||
|
||
// with extra fields but logger class has no "writeExtra" method, calls "write" | ||
// the extra fields to not end up anywhere (ignored) | ||
$this->logger->info( | ||
'extra fields test', [ | ||
'extraFields' => $extraFields | ||
] | ||
); | ||
|
||
// without fields calls "write" always | ||
$this->logger->info('no fields'); | ||
|
||
$logLines = $this->getLogs(); | ||
|
||
$this->assertEquals('1 extra fields test', $logLines[0]); | ||
$this->assertEquals('1 no fields', $logLines[1]); | ||
} | ||
} |