@@ -28,6 +28,7 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
28
28
private $ containerPathPrefix ;
29
29
private $ currentRequest ;
30
30
private $ requestStack ;
31
+ private $ processedLogs ;
31
32
32
33
public function __construct (object $ logger = null , string $ containerPathPrefix = null , RequestStack $ requestStack = null )
33
34
{
@@ -80,6 +81,81 @@ public function getLogs()
80
81
return $ this ->data ['logs ' ] ?? [];
81
82
}
82
83
84
+ public function getProcessedLogs ()
85
+ {
86
+ if (null !== $ this ->processedLogs ) {
87
+ return $ this ->processedLogs ;
88
+ }
89
+
90
+ $ rawLogs = $ this ->getLogs ();
91
+ if ([] === $ rawLogs ) {
92
+ return $ this ->processedLogs = $ rawLogs ;
93
+ }
94
+
95
+ $ logs = [];
96
+ foreach ($ this ->getLogs ()->getValue () as $ rawLog ) {
97
+ $ rawLogData = $ rawLog ->getValue ();
98
+
99
+ if ($ rawLogData ['priority ' ]->getValue () > 300 ) {
100
+ $ logType = 'error ' ;
101
+ } elseif (isset ($ rawLogData ['scream ' ]) && false === $ rawLogData ['scream ' ]->getValue ()) {
102
+ $ logType = 'deprecation ' ;
103
+ } elseif (isset ($ rawLogData ['scream ' ]) && true === $ rawLogData ['scream ' ]->getValue ()) {
104
+ $ logType = 'silenced ' ;
105
+ } else {
106
+ $ logType = 'regular ' ;
107
+ }
108
+
109
+ $ logs [] = [
110
+ 'type ' => $ logType ,
111
+ 'errorCounter ' => isset ($ rawLogData ['errorCounter ' ]) ? $ rawLogData ['errorCounter ' ]->getValue () : 1 ,
112
+ 'timestamp ' => $ rawLogData ['timestamp_rfc3339 ' ]->getValue (),
113
+ 'priority ' => $ rawLogData ['priority ' ]->getValue (),
114
+ 'priorityName ' => $ rawLogData ['priorityName ' ]->getValue (),
115
+ 'channel ' => $ rawLogData ['channel ' ]->getValue (),
116
+ 'message ' => $ rawLogData ['message ' ],
117
+ 'context ' => $ rawLogData ['context ' ],
118
+ ];
119
+ }
120
+
121
+ // sort logs from oldest to newest
122
+ usort ($ logs , static function ($ logA , $ logB ) {
123
+ return $ logA ['timestamp ' ] <=> $ logB ['timestamp ' ];
124
+ });
125
+
126
+ return $ this ->processedLogs = $ logs ;
127
+ }
128
+
129
+ public function getFilters ()
130
+ {
131
+ $ filters = [
132
+ 'channel ' => [],
133
+ 'priority ' => [
134
+ 'Debug ' => 100 ,
135
+ 'Info ' => 200 ,
136
+ 'Warning ' => 300 ,
137
+ 'Error ' => 400 ,
138
+ 'Critical ' => 500 ,
139
+ 'Alert ' => 550 ,
140
+ 'Emergency ' => 600 ,
141
+ ],
142
+ ];
143
+
144
+ $ allChannels = [];
145
+ foreach ($ this ->getProcessedLogs () as $ log ) {
146
+ if ('' === trim ($ log ['channel ' ])) {
147
+ continue ;
148
+ }
149
+
150
+ $ allChannels [] = $ log ['channel ' ];
151
+ }
152
+ $ channels = array_unique ($ allChannels );
153
+ sort ($ channels );
154
+ $ filters ['channel ' ] = $ channels ;
155
+
156
+ return $ filters ;
157
+ }
158
+
83
159
public function getPriorities ()
84
160
{
85
161
return $ this ->data ['priorities ' ] ?? [];
@@ -132,7 +208,7 @@ private function getContainerDeprecationLogs(): array
132
208
$ logs = [];
133
209
foreach (unserialize ($ logContent ) as $ log ) {
134
210
$ log ['context ' ] = ['exception ' => new SilencedErrorContext ($ log ['type ' ], $ log ['file ' ], $ log ['line ' ], $ log ['trace ' ], $ log ['count ' ])];
135
- $ log ['timestamp ' ] = $ bootTime ;
211
+ $ log ['timestamp ' ] = ( new \ DateTimeImmutable ())-> setTimestamp ( $ bootTime)-> format (\DateTimeInterface:: RFC3339_EXTENDED ) ;
136
212
$ log ['priority ' ] = 100 ;
137
213
$ log ['priorityName ' ] = 'DEBUG ' ;
138
214
$ log ['channel ' ] = null ;
0 commit comments