Skip to content

Commit 65a65e1

Browse files
committed
Fix compatibility with Monolog 2
1 parent 7c7d981 commit 65a65e1

File tree

1 file changed

+38
-14
lines changed

1 file changed

+38
-14
lines changed

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

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,43 @@
1212
namespace Symfony\Bridge\Monolog\Handler;
1313

1414
use Monolog\Formatter\FormatterInterface;
15-
use Monolog\Handler\AbstractHandler;
15+
use Monolog\Handler\AbstractProcessingHandler;
16+
use Monolog\Handler\FormattableHandlerTrait;
1617
use Monolog\Logger;
1718
use Symfony\Bridge\Monolog\Formatter\VarDumperFormatter;
1819

20+
if (\trait_exists(FormattableHandlerTrait::class)) {
21+
class ServerLogHandler extends AbstractProcessingHandler
22+
{
23+
use ServerLogHandlerTrait;
24+
25+
/**
26+
* {@inheritdoc}
27+
*/
28+
protected function getDefaultFormatter(): FormatterInterface
29+
{
30+
return new VarDumperFormatter();
31+
}
32+
}
33+
} else {
34+
class ServerLogHandler extends AbstractProcessingHandler
35+
{
36+
use ServerLogHandlerTrait;
37+
38+
/**
39+
* {@inheritdoc}
40+
*/
41+
protected function getDefaultFormatter()
42+
{
43+
return new VarDumperFormatter();
44+
}
45+
}
46+
}
47+
1948
/**
2049
* @author Grégoire Pineau <lyrixx@lyrixx.info>
2150
*/
22-
class ServerLogHandler extends AbstractHandler
51+
trait ServerLogHandlerTrait
2352
{
2453
private $host;
2554
private $context;
@@ -56,6 +85,11 @@ public function handle(array $record): bool
5685
restore_error_handler();
5786
}
5887

88+
return parent::handle($record);
89+
}
90+
91+
protected function write(array $record): void
92+
{
5993
$recordFormatted = $this->formatRecord($record);
6094

6195
set_error_handler(self::class.'::nullErrorHandler');
@@ -72,16 +106,12 @@ public function handle(array $record): bool
72106
} finally {
73107
restore_error_handler();
74108
}
75-
76-
return false === $this->bubble;
77109
}
78110

79111
/**
80112
* {@inheritdoc}
81-
*
82-
* @return FormatterInterface
83113
*/
84-
protected function getDefaultFormatter()
114+
protected function getDefaultFormatter(): FormatterInterface
85115
{
86116
return new VarDumperFormatter();
87117
}
@@ -103,13 +133,7 @@ private function createSocket()
103133

104134
private function formatRecord(array $record): string
105135
{
106-
if ($this->processors) {
107-
foreach ($this->processors as $processor) {
108-
$record = $processor($record);
109-
}
110-
}
111-
112-
$recordFormatted = $this->getFormatter()->format($record);
136+
$recordFormatted = $record['formatted'];
113137

114138
foreach (['log_uuid', 'uuid', 'uid'] as $key) {
115139
if (isset($record['extra'][$key])) {

0 commit comments

Comments
 (0)