Skip to content

Commit 5a30793

Browse files
bug #34697 [MonologBridge] Fix compatibility of ServerLogHandler with Monolog 2 (jderusse)
This PR was merged into the 5.0 branch. Discussion ---------- [MonologBridge] Fix compatibility of ServerLogHandler with Monolog 2 | Q | A | ------------- | --- | Branch? | 5.0 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | #34520 | License | MIT | Doc PR | NA This is an alternative to #34521 that keep compatibility with "processors" and "formaters". Commits ------- bdb10f7 Fix compatibility with Monolog 2
2 parents 7c7d981 + bdb10f7 commit 5a30793

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)
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