Skip to content

[MonologBridge] Fix Monolog/Logger final deprecation #49759

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

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Rolling back Symfony Logger extending Monolog\Logger; Added deprecati…
…on messages
  • Loading branch information
joaojacome committed Mar 28, 2023
commit 9e46c79797eac9ca788bd0bc7d81264d4226701d
20 changes: 10 additions & 10 deletions src/Symfony/Bridge/Monolog/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* @author Fabien Potencier <fabien@symfony.com>
*/
class Logger implements LoggerInterface, DebugLoggerInterface, ResetInterface
class Logger extends BaseLogger implements LoggerInterface, DebugLoggerInterface, ResetInterface
{
use MonologApiTrait;

Expand Down Expand Up @@ -152,47 +152,47 @@ private function getDebugLogger(): ?DebugLoggerInterface
return null;
}

public function emergency(\Stringable|string $message, array $context = []): void
public function emergency($message, array $context = []): void
{
$this->logger->emergency($message, $context);
}

public function alert(\Stringable|string $message, array $context = []): void
public function alert($message, array $context = []): void
{
$this->logger->alert($message, $context);
}

public function critical(\Stringable|string $message, array $context = []): void
public function critical($message, array $context = []): void
{
$this->logger->critical($message, $context);
}

public function error(\Stringable|string $message, array $context = []): void
public function error($message, array $context = []): void
{
$this->logger->error($message, $context);
}

public function warning(\Stringable|string $message, array $context = []): void
public function warning($message, array $context = []): void
{
$this->logger->warning($message, $context);
}

public function notice(\Stringable|string $message, array $context = []): void
public function notice($message, array $context = []): void
{
$this->logger->notice($message, $context);
}

public function info(\Stringable|string $message, array $context = []): void
public function info($message, array $context = []): void
{
$this->logger->info($message, $context);
}

public function debug(\Stringable|string $message, array $context = []): void
public function debug($message, array $context = []): void
{
$this->logger->debug($message, $context);
}

public function log($level, \Stringable|string $message, array $context = []): void
public function log($level, $message, array $context = []): void
{
$this->logger->log($level, $message, $context);
}
Expand Down
31 changes: 16 additions & 15 deletions src/Symfony/Bridge/Monolog/MonologApiTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,50 +32,51 @@ trait MonologApiTrait
* @see BaseLogger::$name
* @deprecated This has been copied over from \Monolog\Logger for compatibility reasons, and might be removed eventually.
*/
protected string $name;
protected $name;

/**
* @see BaseLogger::$handlers
* @deprecated This has been copied over from \Monolog\Logger for compatibility reasons, and might be removed eventually.
*
* @var list<HandlerInterface>
*/
protected array $handlers;
protected $handlers;

/**
* @see BaseLogger::$processors
* @deprecated This has been copied over from \Monolog\Logger for compatibility reasons, and might be removed eventually.
*
* @var array<(callable(LogRecord): LogRecord)|ProcessorInterface>
*/
protected array $processors;
protected $processors;

/**
* @see BaseLogger::$microsecondTimestamps
* @deprecated This has been copied over from \Monolog\Logger for compatibility reasons, and might be removed eventually.
*/
protected bool $microsecondTimestamps = true;
protected $microsecondTimestamps = true;

/**
* @see BaseLogger::$timezone
* @deprecated This has been copied over from \Monolog\Logger for compatibility reasons, and might be removed eventually.
*/
protected DateTimeZone $timezone;
protected $timezone;

/**
* @see BaseLogger::$exceptionHandler
* @deprecated This has been copied over from \Monolog\Logger for compatibility reasons, and might be removed eventually.
*/
protected Closure|null $exceptionHandler = null;
protected $exceptionHandler = null;

/**
* @see BaseLogger::__construct
* @deprecated This has been copied over from \Monolog\Logger for compatibility reasons, and might be removed eventually.
* @deprecated Creating an instance of Monolog\Logger through this method is deprecated. Please use ::setLogger
*/
public function __construct() // string $name, array $handlers = [], array $processors = [], DateTimeZone|null $timezone = null
{
$args = \func_get_args();
if ([] !== $args) {
trigger_deprecation('symfony/monolog-bridge', '6.3', 'The "%s" class extending "%s" is deprecated. In the future, this class will stop extending it.', self::class, BaseLogger::class);
$this->logger = new BaseLogger(...$args);
}
}
Expand Down Expand Up @@ -125,9 +126,9 @@ public function popHandler(): HandlerInterface
* @see BaseLogger::removeHandler
* @deprecated This has been copied over from \Monolog\Logger for compatibility reasons, and might be removed eventually.
*/
public function removeHandler(int $handlerIndex): void
public function removeHandler(callable $callback): void
{
$this->logger->removeHandler($handlerIndex);
$this->logger->removeHandler($callback);
}

/**
Expand Down Expand Up @@ -174,9 +175,9 @@ public function popProcessor(): callable
* @see BaseLogger::removeProcessor
* @deprecated This has been copied over from \Monolog\Logger for compatibility reasons, and might be removed eventually.
*/
public function removeProcessor(int $processorIndex): void
public function removeProcessor(callable $callback): void
{
$this->logger->removeProcessor($processorIndex);
$this->logger->removeProcessor($callback);
}

/**
Expand Down Expand Up @@ -241,7 +242,7 @@ public static function getLevelName(int|Level $level): string
* @see BaseLogger::toMonologLevel
* @deprecated This has been copied over from \Monolog\Logger for compatibility reasons, and might be removed eventually.
*/
public static function toMonologLevel(string|int|Level $level): Level
public static function toMonologLevel($level): int
{
return BaseLogger::toMonologLevel($level);
}
Expand All @@ -259,7 +260,7 @@ public function isHandling(int|string|Level $level): bool
* @see BaseLogger::setExceptionHandler
* @deprecated This has been copied over from \Monolog\Logger for compatibility reasons, and might be removed eventually.
*/
public function setExceptionHandler(Closure|null $callback): self
public function setExceptionHandler(?callable $callback): self
{
$this->logger->setExceptionHandler($callback);

Expand All @@ -270,7 +271,7 @@ public function setExceptionHandler(Closure|null $callback): self
* @see BaseLogger::getExceptionHandler
* @deprecated This has been copied over from \Monolog\Logger for compatibility reasons, and might be removed eventually.
*/
public function getExceptionHandler(): Closure|null
public function getExceptionHandler(): ?callable
{
return $this->logger->getExceptionHandler();
}
Expand Down Expand Up @@ -299,7 +300,7 @@ public function getTimezone(): DateTimeZone
* @see BaseLogger::handleException
* @deprecated This has been copied over from \Monolog\Logger for compatibility reasons, and might be removed eventually.
*/
protected function handleException(Throwable $e, LogRecord $record): void
protected function handleException(Throwable $e, array $record): void
{
$this->logger->handleException($e, $record);
}
Expand Down
12 changes: 12 additions & 0 deletions src/Symfony/Bridge/Monolog/Tests/LegacyLoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,22 @@
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Monolog\Logger;
use Symfony\Bridge\Monolog\Processor\DebugProcessor;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\HttpFoundation\Request;

/**
* @group legacy
*/
class LegacyLoggerTest extends TestCase
{
use ExpectDeprecationTrait;

public function testConstructWillTriggerDeprecation()
{
$this->expectDeprecation('Since symfony/monolog-bridge 6.3: The "Symfony\Bridge\Monolog\Logger" class extending "Monolog\Logger" is deprecated. In the future, this class will stop extending it.');
new Logger(__METHOD__);
}

public function testGetLogsWithoutDebugProcessor()
{
$handler = new TestHandler();
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Bridge/Monolog/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"monolog/monolog": "dev-remove-handlers-processors",
"symfony/service-contracts": "^2.5|^3",
"symfony/http-kernel": "^5.4|^6.0",
"psr/log": "^2.0 || ^3.0"
"psr/log": "^2.0 || ^3.0",
"symfony/deprecation-contracts": "^2.5|^3"
},
"require-dev": {
"symfony/console": "^5.4|^6.0",
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy