8000 [Monolog] Really reset logger when calling logger::reset() by lyrixx · Pull Request #30410 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Monolog] Really reset logger when calling logger::reset() #30410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Symfony/Bridge/Monolog/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bridge\Monolog;

use Monolog\Logger as BaseLogger;
use Monolog\ResettableInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
use Symfony\Contracts\Service\ResetInterface;
Expand Down Expand Up @@ -73,6 +74,10 @@ public function clear()
public function reset()
{
$this->clear();

if ($this instanceof ResettableInterface) {
parent::reset();
}
}

/**
Expand Down
17 changes: 17 additions & 0 deletions src/Symfony/Bridge/Monolog/Tests/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bridge\Monolog\Tests;

use Monolog\Handler\TestHandler;
use Monolog\ResettableInterface;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Monolog\Logger;
use Symfony\Bridge\Monolog\Processor\DebugProcessor;
Expand Down Expand Up @@ -108,6 +109,22 @@ public function testClear()
$this->assertSame(0, $logger->countErrors());
}

public function testReset()
{
$handler = new TestHandler();
$logger = new Logger('test', [$handler]);
$logger->pushProcessor(new DebugProcessor());

$logger->info('test');
$logger->reset();

$this->assertEmpty($logger->getLogs());
$this->assertSame(0, $logger->countErrors());
if (class_exists(ResettableInterface::class)) {
$this->assertEmpty($handler->getRecords());
}
}

/**
* @group legacy
* @expectedDeprecation The "Symfony\Bridge\Monolog\Logger::getLogs()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2.
Expand Down
0