1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-02 11:20:31 +02:00
This commit is contained in:
Jordi Boggiano
2024-06-28 10:48:40 +02:00
parent 3ba77d1d39
commit 07cd08e0e4
34 changed files with 106 additions and 91 deletions

View File

@@ -244,6 +244,7 @@ class LineFormatter extends NormalizerFormatter
$str = preg_replace('/(?<!\\\\)\\\\[rn]/', "\n", $str);
if (null === $str) {
$pcreErrorCode = preg_last_error();
throw new \RuntimeException('Failed to run preg_replace: ' . $pcreErrorCode . ' / ' . Utils::pcreLastErrorMessage($pcreErrorCode));
}
}

View File

@@ -44,7 +44,6 @@ class SyslogFormatter extends LineFormatter
}
/**
* @param LogRecord $record
* @return array<string, mixed>
*/
private function formatExtra(LogRecord $record): array

View File

@@ -65,6 +65,7 @@ class AmqpHandler extends AbstractProcessingHandler
public function setExtraAttributes(array $extraAttributes): self
{
$this->extraAttributes = $extraAttributes;
return $this;
}
@@ -155,6 +156,7 @@ class AmqpHandler extends AbstractProcessingHandler
if (\count($this->extraAttributes) > 0) {
$attributes = array_merge($attributes, $this->extraAttributes);
}
return new AMQPMessage($data, $attributes);
}

View File

@@ -17,7 +17,6 @@ use Monolog\Utils;
use Monolog\LogRecord;
use Monolog\Level;
use function count;
use function headers_list;
use function stripos;

View File

@@ -14,7 +14,6 @@ namespace Monolog\Handler;
use Monolog\Level;
use Monolog\Formatter\FormatterInterface;
use Monolog\Formatter\LogglyFormatter;
use function array_key_exists;
use CurlHandle;
use Monolog\LogRecord;

View File

@@ -182,8 +182,8 @@ class RotatingFileHandler extends StreamHandler
[$fileInfo['filename'], str_replace(
['Y', 'y', 'm', 'd'],
['[0-9][0-9][0-9][0-9]', '[0-9][0-9]', '[0-9][0-9]', '[0-9][0-9]'],
$this->dateFormat)
],
$this->dateFormat
)],
($fileInfo['dirname'] ?? '') . '/' . $this->filenameFormat
);
if (isset($fileInfo['extension'])) {

View File

@@ -125,6 +125,7 @@ class StreamHandler extends AbstractProcessingHandler
set_error_handler(function (...$args) {
return $this->customErrorHandler(...$args);
});
try {
$stream = fopen($url, 'a');
if ($this->filePermission !== null) {

View File

@@ -13,7 +13,6 @@ namespace Monolog\Handler;
use Closure;
use Monolog\Level;
use Monolog\Logger;
use Monolog\LogRecord;
use Monolog\Utils;
use Monolog\Formatter\FormatterInterface;
@@ -82,6 +81,7 @@ class SymfonyMailerHandler extends MailHandler
if (!$message instanceof Email) {
$record = reset($records);
throw new \InvalidArgumentException('Could not resolve message as instance of Email or a callable returning it' . ($record instanceof LogRecord ? Utils::getRecordMessageForException($record) : ''));
}

View File

@@ -12,7 +12,6 @@
namespace Monolog\Handler;
use Monolog\Level;
use Monolog\Utils;
use Monolog\LogRecord;
/**

View File

@@ -346,6 +346,7 @@ class Logger implements LoggerInterface, ResettableInterface
if ($logDepth === 3) {
$this->warning('A possible infinite logging loop was detected and aborted. It appears some of your handler code is triggering logging, see the previous log record for a hint as to what may be the cause.');
return false;
} elseif ($logDepth >= 5) { // log depth 4 is let through, so we can log the warning above
return false;

View File

@@ -1,4 +1,13 @@
<?php
<?php declare(strict_types=1);
/*
* This file is part of the Monolog package.
*
* (c) Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Monolog\Attribute;
@@ -11,5 +20,4 @@ class WithMonologChannelTest extends TestCase
$attribute = new WithMonologChannel('fixture');
$this->assertSame('fixture', $attribute->channel);
}
}

View File

@@ -121,7 +121,7 @@ class JsonFormatterTest extends TestCase
public function testBasePathWithException(): void
{
$formatter = new JsonFormatter();
$formatter->setBasePath(dirname(dirname(dirname(__DIR__))));
$formatter->setBasePath(\dirname(\dirname(\dirname(__DIR__))));
$exception = new \RuntimeException('Foo');
$message = $this->formatRecordWithExceptionInContext($formatter, $exception);

View File

@@ -84,7 +84,7 @@ class NormalizerFormatterTest extends TestCase
public function testFormatExceptionWithBasePath(): void
{
$formatter = new NormalizerFormatter('Y-m-d');
$formatter->setBasePath(dirname(dirname(dirname(__DIR__))));
$formatter->setBasePath(\dirname(\dirname(\dirname(__DIR__))));
$e = new \LogicException('bar');
$formatted = $formatter->normalizeValue([
'exception' => $e,

View File

@@ -103,16 +103,25 @@ class RedisHandlerTest extends TestCase
{
$redis = new class extends \Predis\Client {
public array $testResults = [];
public function rpush(...$args) {
public function rpush(...$args)
{
$this->testResults[] = ['rpush', ...$args];
return $this;
}
public function ltrim(...$args) {
public function ltrim(...$args)
{
$this->testResults[] = ['ltrim', ...$args];
return $this;
}
public function transaction(...$args) {
public function transaction(...$args)
{
$this->testResults[] = ['transaction start'];
return ($args[0])($this);
}
};

View File

@@ -59,7 +59,8 @@ class RotatingFileHandlerTest extends TestCase
unset($this->lastError);
}
private function rrmdir($directory) {
private function rrmdir($directory)
{
if (! is_dir($directory)) {
throw new InvalidArgumentException("$directory must be a directory");
}

View File

@@ -69,6 +69,7 @@ class SymfonyMailerHandlerTest extends TestCase
// Callback dynamically changes subject based on number of logged records
$callback = function ($content, array $records) use ($expectedMessage) {
$subject = \count($records) > 0 ? 'Emergency' : 'Normal';
return $expectedMessage->subject($subject);
};
$handler = new SymfonyMailerHandler($this->mailer, $callback);

View File

@@ -285,11 +285,11 @@ class LoggerTest extends TestCase
$handler->expects($this->any())
->method('isHandling')
->willReturn(true);
;
$handler->expects($this->any())
->method('handle')
->willReturn(true);
;
$logger->pushHandler($handler);
$processor = $this->getMockBuilder('Monolog\Processor\WebProcessor')
@@ -316,7 +316,7 @@ class LoggerTest extends TestCase
$handler->expects($this->once())
->method('isHandling')
->willReturn(false);
;
$logger->pushHandler($handler);
$that = $this;
$logger->pushProcessor(function ($record) use ($that) {
@@ -337,29 +337,29 @@ class LoggerTest extends TestCase
$handler1->expects($this->never())
->method('isHandling')
->willReturn(false);
;
$handler1->expects($this->once())
->method('handle')
->willReturn(false);
;
$logger->pushHandler($handler1);
$handler2 = $this->createMock('Monolog\Handler\HandlerInterface');
$handler2->expects($this->once())
->method('isHandling')
->willReturn(true);
;
$handler2->expects($this->once())
->method('handle')
->willReturn(false);
;
$logger->pushHandler($handler2);
$handler3 = $this->createMock('Monolog\Handler\HandlerInterface');
$handler3->expects($this->once())
->method('isHandling')
->willReturn(false);
;
$handler3->expects($this->never())
->method('handle')
;
@@ -377,27 +377,25 @@ class LoggerTest extends TestCase
$handler1->expects($this->never())
->method('isHandling')
->willReturn(false);
;
$handler1->expects($this->once())
->method('handle')
->willReturn(false);
;
$handler2 = $this->createMock('Monolog\Handler\HandlerInterface');
$handler2->expects($this->once())
->method('isHandling')
->willReturn(true);
;
$handler2->expects($this->once())
->method('handle')
->willReturn(false);
;
$handler3 = $this->createMock('Monolog\Handler\HandlerInterface');
$handler3->expects($this->once())
->method('isHandling')
->willReturn(false);
;
$handler3->expects($this->never())
->method('handle')
;
@@ -419,22 +417,22 @@ class LoggerTest extends TestCase
$handler1->expects($this->any())
->method('isHandling')
->willReturn(true);
;
$handler1->expects($this->once())
->method('handle')
->willReturn(false);
;
$logger->pushHandler($handler1);
$handler2 = $this->createMock('Monolog\Handler\HandlerInterface');
$handler2->expects($this->any())
->method('isHandling')
->willReturn(true);
;
$handler2->expects($this->once())
->method('handle')
->willReturn(false);
;
$logger->pushHandler($handler2);
$logger->debug('test');
@@ -451,7 +449,7 @@ class LoggerTest extends TestCase
$handler1->expects($this->any())
->method('isHandling')
->willReturn(true);
;
$handler1->expects($this->never())
->method('handle')
;
@@ -461,11 +459,11 @@ class LoggerTest extends TestCase
$handler2->expects($this->any())
->method('isHandling')
->willReturn(true);
;
$handler2->expects($this->once())
->method('handle')
->willReturn(true);
;
$logger->pushHandler($handler2);
$logger->debug('test');
@@ -482,7 +480,6 @@ class LoggerTest extends TestCase
$handler1->expects($this->any())
->method('isHandling')
->willReturn(false);
;
$logger->pushHandler($handler1);
$this->assertFalse($logger->isHandling(Level::Debug));
@@ -491,7 +488,6 @@ class LoggerTest extends TestCase
$handler2->expects($this->any())
->method('isHandling')
->willReturn(true);
;
$logger->pushHandler($handler2);
$this->assertTrue($logger->isHandling(Level::Debug));
@@ -677,7 +673,7 @@ class LoggerTest extends TestCase
$handler->expects($this->any())
->method('isHandling')
->willReturn(true);
;
$handler->expects($this->any())
->method('handle')
->will($this->throwException(new \Exception('Some handler exception')))
@@ -706,7 +702,7 @@ class LoggerTest extends TestCase
$handler->expects($this->any())
->method('isHandling')
->willReturn(true);
;
$handler->expects($this->any())
->method('handle')
->will($this->throwException(new \Exception('Some handler exception')))
@@ -900,7 +896,6 @@ class LoggingHandler implements HandlerInterface
}
}
class FiberSuspendHandler implements HandlerInterface
{
public function isHandling(LogRecord $record): bool