Skip to content

Commit

Permalink
Fix: LoggerHolder compatibility with Monolog >= 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMikes authored and f3l1x committed Jan 26, 2024
1 parent 85511b3 commit e0c8ca4
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/LoggerHolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Contributte\Monolog\Exception\Logic\InvalidStateException;
use Monolog\Logger;
use Monolog\LogRecord;
use Nette\DI\Container;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -60,11 +61,21 @@ public function getLogger(): LoggerInterface
$logger = clone $this->instLogger;

// Write in log which class used LoggerHolder
$logger->pushProcessor(function (array $record) use ($calledBy): array {
$record['extra']['calledBy'] = $calledBy;
// Monolog >= 3.0
if (class_exists(LogRecord::class)) {
$logger->pushProcessor(function (LogRecord $record) use ($calledBy): LogRecord {
$record->extra['calledBy'] = $calledBy;

return $record;
});
} else {
$logger->pushProcessor(function (array $record) use ($calledBy): array {

Check failure on line 72 in src/LoggerHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan / Phpstan (8.1)

Parameter #1 $callback of method Monolog\Logger::pushProcessor() expects callable(Monolog\LogRecord): Monolog\LogRecord, Closure(array): non-empty-array given.

Check failure on line 72 in src/LoggerHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan / Phpstan (8.1)

Parameter #1 $callback of method Monolog\Logger::pushProcessor() expects callable(Monolog\LogRecord): Monolog\LogRecord, Closure(array): non-empty-array given.

Check failure on line 72 in src/LoggerHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan / Phpstan (8.1)

Parameter #1 $callback of method Monolog\Logger::pushProcessor() expects callable(Monolog\LogRecord): Monolog\LogRecord, Closure(array): non-empty-array given.

Check failure on line 72 in src/LoggerHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan / Phpstan (8.1)

Parameter #1 $callback of method Monolog\Logger::pushProcessor() expects callable(Monolog\LogRecord): Monolog\LogRecord, Closure(array): non-empty-array given.

Check failure on line 72 in src/LoggerHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan / Phpstan (8.1)

Parameter #1 $callback of method Monolog\Logger::pushProcessor() expects callable(Monolog\LogRecord): Monolog\LogRecord, Closure(array): non-empty-array given.

Check failure on line 72 in src/LoggerHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan / Phpstan (8.1)

Parameter #1 $callback of method Monolog\Logger::pushProcessor() expects callable(Monolog\LogRecord): Monolog\LogRecord, Closure(array): non-empty-array given.

Check failure on line 72 in src/LoggerHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan / Phpstan (8.1)

Parameter #1 $callback of method Monolog\Logger::pushProcessor() expects callable(Monolog\LogRecord): Monolog\LogRecord, Closure(array): non-empty-array given.

Check failure on line 72 in src/LoggerHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan / Phpstan (8.1)

Parameter #1 $callback of method Monolog\Logger::pushProcessor() expects callable(Monolog\LogRecord): Monolog\LogRecord, Closure(array): non-empty-array given.

Check failure on line 72 in src/LoggerHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan / Phpstan (8.1)

Parameter #1 $callback of method Monolog\Logger::pushProcessor() expects callable(Monolog\LogRecord): Monolog\LogRecord, Closure(array): non-empty-array given.

Check failure on line 72 in src/LoggerHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan / Phpstan (8.1)

Parameter #1 $callback of method Monolog\Logger::pushProcessor() expects callable(Monolog\LogRecord): Monolog\LogRecord, Closure(array): non-empty-array given.

Check failure on line 72 in src/LoggerHolder.php

View workflow job for this annotation

GitHub Actions / PHPStan / Phpstan (8.1)

Parameter #1 $callback of method Monolog\Logger::pushProcessor() expects callable(Monolog\LogRecord): Monolog\LogRecord, Closure(array): non-empty-array given.
$record['extra']['calledBy'] = $calledBy;

return $record;
});
}

return $record;
});

return $logger;
}
Expand Down

0 comments on commit e0c8ca4

Please sign in to comment.