[Monolog] Really reset logger when calling logger::reset()
This commit is contained in:
parent
675c45850c
commit
08a20ee0ba
@ -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;
|
||||
@ -73,6 +74,10 @@ class Logger extends BaseLogger implements DebugLoggerInterface, ResetInterface
|
||||
public function reset()
|
||||
{
|
||||
$this->clear();
|
||||
|
||||
if ($this instanceof ResettableInterface) {
|
||||
parent::reset();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
@ -108,6 +109,22 @@ class LoggerTest extends TestCase
|
||||
$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.
|
||||
|
Reference in New Issue
Block a user