Skip to content

Commit 1ecbc0b

Browse files
committed
[MonologBridge] Remove support for monolog < 3
1 parent ffe6f08 commit 1ecbc0b

33 files changed

+192
-499
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
"guzzlehttp/promises": "^1.4",
137137
"league/html-to-markdown": "^5.0",
138138
"masterminds/html5": "^2.7.2",
139-
"monolog/monolog": "^1.25.1|^2",
139+
"monolog/monolog": "^3",
140140
"nyholm/psr7": "^1.0",
141141
"pda/pheanstalk": "^4.0",
142142
"php-http/discovery": "^1.15",

src/Symfony/Bridge/Monolog/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.0
5+
---
6+
7+
* Drop support for monolog < 3.0
8+
49
6.4
510
---
611

src/Symfony/Bridge/Monolog/Command/ServerLogCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
use Monolog\Formatter\FormatterInterface;
1515
use Monolog\Handler\HandlerInterface;
16-
use Monolog\Logger;
16+
use Monolog\Level;
17+
use Monolog\LogRecord;
1718
use Symfony\Bridge\Monolog\Formatter\ConsoleFormatter;
1819
use Symfony\Bridge\Monolog\Handler\ConsoleHandler;
1920
use Symfony\Component\Console\Attribute\AsCommand;
@@ -86,7 +87,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8687
}
8788

8889
$this->handler = new ConsoleHandler($output, true, [
89-
OutputInterface::VERBOSITY_NORMAL => Logger::DEBUG,
90+
OutputInterface::VERBOSITY_NORMAL => Level::Debug,
9091
]);
9192

9293
$this->handler->setFormatter(new ConsoleFormatter([
@@ -145,7 +146,7 @@ private function getLogs($socket): iterable
145146
}
146147
}
147148

148-
private function displayLog(OutputInterface $output, int $clientId, array $record): void
149+
private function displayLog(OutputInterface $output, int $clientId, LogRecord $record): void
149150
{
150151
if (isset($record['log_id'])) {
151152
$clientId = unpack('H*', $record['log_id'])[1];

src/Symfony/Bridge/Monolog/Formatter/CompatibilityFormatter.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Bridge\Monolog\Formatter;
1313

1414
use Monolog\Formatter\FormatterInterface;
15-
use Monolog\Logger;
15+
use Monolog\Level;
1616
use Monolog\LogRecord;
1717
use Symfony\Component\Console\Formatter\OutputFormatter;
1818
use Symfony\Component\VarDumper\Cloner\Data;
@@ -28,20 +28,18 @@
2828
*/
2929
final class ConsoleFormatter implements FormatterInterface
3030
{
31-
use CompatibilityFormatter;
32-
3331
public const SIMPLE_FORMAT = "%datetime% %start_tag%%level_name%%end_tag% <comment>[%channel%]</> %message%%context%%extra%\n";
3432
public const SIMPLE_DATE = 'H:i:s';
3533

3634
private const LEVEL_COLOR_MAP = [
37-
Logger::DEBUG => 'fg=white',
38-
Logger::INFO => 'fg=green',
39-
Logger::NOTICE => 'fg=blue',
40-
Logger::WARNING => 'fg=cyan',
41-
Logger::ERROR => 'fg=yellow',
42-
Logger::CRITICAL => 'fg=red',
43-
Logger::ALERT => 'fg=red',
44-
Logger::EMERGENCY => 'fg=white;bg=red',
35+
Level::Debug->value => 'fg=white',
36+
Level::Info->value => 'fg=green',
37+
Level::Notice->value => 'fg=blue',
38+
Level::Warning->value => 'fg=cyan',
39+
Level::Error->value => 'fg=yellow',
40+
Level::Critical->value => 'fg=red',
41+
Level::Alert->value => 'fg=red',
42+
Level::Emergency->value => 'fg=white;bg=red',
4543
];
4644

4745
private array $options;
@@ -98,11 +96,9 @@ public function formatBatch(array $records): mixed
9896
return $records;
9997
}
10098

101-
private function doFormat(array|LogRecord $record): mixed
99+
public function format(LogRecord $record): mixed
102100
{
103-
if ($record instanceof LogRecord) {
104-
$record = $record->toArray();
105-
}
101+
$record = $record->toArray();
106102
$record = $this->replacePlaceHolder($record);
107103

108104
if (!$this->options['ignore_empty_context_and_extra'] || !empty($record['context'])) {

src/Symfony/Bridge/Monolog/Formatter/VarDumperFormatter.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,16 @@
2020
*/
2121
final class VarDumperFormatter implements FormatterInterface
2222
{
23-
use CompatibilityFormatter;
24-
2523
private VarCloner $cloner;
2624

2725
public function __construct(VarCloner $cloner = null)
2826
{
2927
$this->cloner = $cloner ?? new VarCloner();
3028
}
3129

32-
private function doFormat(array|LogRecord $record): mixed
30+
public function format(LogRecord $record): mixed
3331
{
34-
if ($record instanceof LogRecord) {
35-
$record = $record->toArray();
36-
}
32+
$record = $record->toArray();
3733

3834
$record['context'] = $this->cloner->cloneVar($record['context']);
3935
$record['extra'] = $this->cloner->cloneVar($record['extra']);

src/Symfony/Bridge/Monolog/Handler/CompatibilityHandler.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/Symfony/Bridge/Monolog/Handler/CompatibilityProcessingHandler.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/Symfony/Bridge/Monolog/Handler/ConsoleHandler.php

Lines changed: 11 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Monolog\Formatter\FormatterInterface;
1515
use Monolog\Formatter\LineFormatter;
1616
use Monolog\Handler\AbstractProcessingHandler;
17-
use Monolog\Logger;
17+
use Monolog\Level;
1818
use Monolog\LogRecord;
1919
use Symfony\Bridge\Monolog\Formatter\ConsoleFormatter;
2020
use Symfony\Component\Console\ConsoleEvents;
@@ -25,42 +25,6 @@
2525
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
2626
use Symfony\Component\VarDumper\Dumper\CliDumper;
2727

28-
if (Logger::API >= 3) {
29-
/**
30-
* The base class for compatibility between Monolog 3 LogRecord and Monolog 1/2 array records.
31-
*
32-
* @author Jordi Boggiano <j.boggiano@seld.be>
33-
*
34-
* @internal
35-
*/
36-
trait CompatibilityIsHandlingHandler
37-
{
38-
abstract private function doIsHandling(array|LogRecord $record): bool;
39-
40-
public function isHandling(LogRecord $record): bool
41-
{
42-
return $this->doIsHandling($record);
43-
}
44-
}
45-
} else {
46-
/**
47-
* The base class for compatibility between Monolog 3 LogRecord and Monolog 1/2 array records.
48-
*
49-
* @author Jordi Boggiano <j.boggiano@seld.be>
50-
*
51-
* @internal
52-
*/
53-
trait CompatibilityIsHandlingHandler
54-
{
55-
abstract private function doIsHandling(array|LogRecord $record): bool;
56-
57-
public function isHandling(array $record): bool
58-
{
59-
return $this->doIsHandling($record);
60-
}
61-
}
62-
}
63-
6428
/**
6529
* Writes logs to the console output depending on its verbosity setting.
6630
*
@@ -80,17 +44,13 @@ public function isHandling(array $record): bool
8044
*/
8145
final class ConsoleHandler extends AbstractProcessingHandler implements EventSubscriberInterface
8246
{
83-
use CompatibilityHandler;
84-
use CompatibilityIsHandlingHandler;
85-
use CompatibilityProcessingHandler;
86-
8747
private ?OutputInterface $output;
8848
private array $verbosityLevelMap = [
89-
OutputInterface::VERBOSITY_QUIET => Logger::ERROR,
90-
OutputInterface::VERBOSITY_NORMAL => Logger::WARNING,
91-
OutputInterface::VERBOSITY_VERBOSE => Logger::NOTICE,
92-
OutputInterface::VERBOSITY_VERY_VERBOSE => Logger::INFO,
93-
OutputInterface::VERBOSITY_DEBUG => Logger::DEBUG,
49+
OutputInterface::VERBOSITY_QUIET => Level::Error,
50+
OutputInterface::VERBOSITY_NORMAL => Level::Warning,
51+
OutputInterface::VERBOSITY_VERBOSE => Level::Notice,
52+
OutputInterface::VERBOSITY_VERY_VERBOSE => Level::Info,
53+
OutputInterface::VERBOSITY_DEBUG => Level::Debug,
9454
];
9555
private array $consoleFormatterOptions;
9656

@@ -103,7 +63,7 @@ final class ConsoleHandler extends AbstractProcessingHandler implements EventSub
10363
*/
10464
public function __construct(OutputInterface $output = null, bool $bubble = true, array $verbosityLevelMap = [], array $consoleFormatterOptions = [])
10565
{
106-
parent::__construct(Logger::DEBUG, $bubble);
66+
parent::__construct(Level::Debug, $bubble);
10767
$this->output = $output;
10868

10969
if ($verbosityLevelMap) {
@@ -113,12 +73,12 @@ public function __construct(OutputInterface $output = null, bool $bubble = true,
11373
$this->consoleFormatterOptions = $consoleFormatterOptions;
11474
}
11575

116-
private function doIsHandling(array|LogRecord $record): bool
76+
public function isHandling(LogRecord $record): bool
11777
{
11878
return $this->updateLevel() && parent::isHandling($record);
11979
}
12080

121-
private function doHandle(array|LogRecord $record): bool
81+
public function handle(LogRecord $record): bool
12282
{
12383
// we have to update the logging level each time because the verbosity of the
12484
// console output might have changed in the meantime (it is not immutable)
@@ -173,7 +133,7 @@ public static function getSubscribedEvents(): array
173133
];
174134
}
175135

176-
private function doWrite(array|LogRecord $record): void
136+
protected function write(LogRecord $record): void
177137
{
178138
// at this point we've determined for sure that we want to output the record, so use the output's own verbosity
179139
$this->output->write((string) $record['formatted'], false, $this->output->getVerbosity());
@@ -209,7 +169,7 @@ private function updateLevel(): bool
209169
if (isset($this->verbosityLevelMap[$verbosity])) {
210170
$this->setLevel($this->verbosityLevelMap[$verbosity]);
211171
} else {
212-
$this->setLevel(Logger::DEBUG);
172+
$this->setLevel(Level::Debug);
213173
}
214174

215175
return true;

0 commit comments

Comments
 (0)