12
12
namespace Symfony \Bridge \Monolog \Handler ;
13
13
14
14
use Monolog \Formatter \FormatterInterface ;
15
- use Monolog \Handler \AbstractHandler ;
15
+ use Monolog \Handler \AbstractProcessingHandler ;
16
+ use Monolog \Handler \FormattableHandlerTrait ;
16
17
use Monolog \Logger ;
17
18
use Symfony \Bridge \Monolog \Formatter \VarDumperFormatter ;
18
19
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
+
19
48
/**
20
49
* @author Grégoire Pineau <lyrixx@lyrixx.info>
21
50
*/
22
- class ServerLogHandler extends AbstractHandler
51
+ trait ServerLogHandlerTrait
23
52
{
24
53
private $ host ;
25
54
private $ context ;
@@ -56,6 +85,11 @@ public function handle(array $record): bool
56
85
restore_error_handler ();
57
86
}
58
87
88
+ return parent ::handle ($ record );
89
+ }
90
+
91
+ protected function write (array $ record ): void
92
+ {
59
93
$ recordFormatted = $ this ->formatRecord ($ record );
60
94
61
95
set_error_handler (self ::class.'::nullErrorHandler ' );
@@ -72,16 +106,12 @@ public function handle(array $record): bool
72
106
} finally {
73
107
restore_error_handler ();
74
108
}
75
-
76
- return false === $ this ->bubble ;
77
109
}
78
110
79
111
/**
80
112
* {@inheritdoc}
81
- *
82
- * @return FormatterInterface
83
113
*/
84
- protected function getDefaultFormatter ()
114
+ protected function getDefaultFormatter (): FormatterInterface
85
115
{
86
116
return new VarDumperFormatter ();
87
117
}
@@ -103,13 +133,7 @@ private function createSocket()
103
133
104
134
private function formatRecord (array $ record ): string
105
135
{
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 ' ];
113
137
114
138
foreach (['log_uuid ' , 'uuid ' , 'uid ' ] as $ key ) {
115
139
if (isset ($ record ['extra ' ][$ key ])) {
0 commit comments