8000 [MonologBridge] Fix Monolog/Logger final deprecation by joaojacome · Pull Request #49759 · symfony/symfony · GitHub
[go: up one dir, main page]

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 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
134 changes: 117 additions & 17 deletions src/Symfony/Bridge/Monolog/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,83 @@

namespace Symfony\Bridge\Monolog;

use Monolog\Handler\HandlerInterface;
use Monolog\Logger as BaseLogger;
use Monolog\Processor\ProcessorInterface;
use Monolog\ResettableInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
use Symfony\Contracts\Service\ResetInterface;

/**
* @author Fabien Potencier <fabien@symfony.com>
*/
class Logger extends BaseLogger implements DebugLoggerInterface, ResetInterface
class Logger extends BaseLogger implements LoggerInterface, DebugLoggerInterface, ResetInterface
{
use MonologApiTrait;

/**
* @see BaseLogger::DEBUG
* @deprecated This has been copied over from \Monolog\Logger for compatibility reasons, and might be removed eventually.
*/
public const DEBUG = 100;

/**
* @see BaseLogger::INFO
* @deprecated This has been copied over from \Monolog\Logger for compatibility reasons, and might be removed eventually.
*/
public const INFO = 200;

/**
* @see BaseLogger::NOTICE
* @deprecated This has been copied over from \Monolog\Logger for compatibility reasons, and might be removed eventually..
*/
public const NOTICE = 250;

/**
* @see BaseLogger::WARNING
* @deprecated This has been copied over from \Monolog\Logger for compatibility reasons, and might be removed eventually.
*/
public const WARNING = 300;

/**
* @see BaseLogger::ERROR
* @deprecated This has been copied over from \Monolog\Logger for compatibility reasons, and might be removed eventually.
*/
public const ERROR = 400;

/**
* @see BaseLogger::CRITICAL
* @deprecated This has been copied over from \Monolog\Logger for compatibility reasons, and might be removed eventually.
*/
public const CRITICAL = 500;

/**
* @see BaseLogger::ALERT
* @deprecated This has been copied over from \Monolog\Logger for compatibility reasons, and might be removed eventually.
*/
public const ALERT = 550;

/**
* @see BaseLogger::EMERGENCY
* @deprecated This has been copied over from \Monolog\Logger for compatibility reasons, and might be removed eventually.
*/
public const EMERGENCY = 600;

/**
* @see BaseLogger::API
* @deprecated This has been copied over from \Monolog\Logger for compatibility reasons, and might be removed eventually.
*/
public const API = 3;

public function setLogger(BaseLogger $logger): self
{
$this->logger = $logger;

return $this;
}

public function getLogs(Request $request = null): array
{
if ($logger = $this->getDebugLogger()) {
Expand Down Expand Up @@ -54,46 +120,80 @@ public function reset(): void
{
$this->clear();

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

/**
* @return void
*/
public function removeDebugLogger()
{
foreach ($this->processors as $k => $processor) {
if ($processor instanceof DebugLoggerInterface) {
unset($this->processors[$k]);
}
}

foreach ($this->handlers as $k => $handler) {
if ($handler instanceof DebugLoggerInterface) {
unset($this->handlers[$k]);
}
}
$this->logger->removeProcessor(fn (int $key, ProcessorInterface $processor) => $processor instanceof DebugLoggerInterface);
$this->logger->removeHandler(fn (int $key, HandlerInterface $handler) => $handler instanceof DebugLoggerInterface);
}

/**
* Returns a DebugLoggerInterface instance if one is registered with this logger.
*/
private function getDebugLogger(): ?DebugLoggerInterface
{
foreach ($this->processors as $processor) {
foreach ($this->logger->getProcessors() as $processor) {
if ($processor instanceof DebugLoggerInterface) {
return $processor;
}
}

foreach ($this->handlers as $handler) {
foreach ($this->logger->getHandlers() as $handler) {
if ($handler instanceof DebugLoggerInterface) {
return $handler;
}
}

return null;
}

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

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

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

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

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

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

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

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

public function log($level, $message, array $context = []): void
{
$this->logger->log($level, $message, $context);
}
}
Loading
0