@@ -40,7 +40,7 @@ class ChromeLogger extends AbstractRoute
4040 'events ' ,
4141 'files ' ,
4242 ],
43- 'group ' => true , // contain/wrap log in a group?
43+ 'group ' => false , // contain/wrap log in a group?
4444 );
4545
4646 /** @var list<string> */
@@ -102,14 +102,15 @@ public function processLogEntries($event = null)
102102 \bdk \Debug \Utility \PhpType::assertType ($ event , 'bdk\PubSub\Event|null ' );
103103
104104 $ this ->dumper ->crateRaw = false ;
105+
105106 $ this ->data = $ this ->debug ->data ->get ();
106107 $ this ->data ['log ' ] = \array_values ($ this ->data ['log ' ]);
107- $ this ->processChannels ();
108+ $ this ->buildJsonData ();
108109 $ this ->max = $ this ->getMaxLength ();
109110 $ encoded = $ this ->encode ($ this ->jsonData );
110111 if ($ this ->max && \strlen ($ encoded ) > $ this ->max ) {
111112 $ this ->reduceData ();
112- $ this ->processChannels ();
113+ $ this ->buildJsonData ();
113114 $ encoded = $ this ->encode ($ this ->jsonData );
114115 $ encoded = $ this ->assertEncodedLength ($ encoded );
115116 }
@@ -164,14 +165,28 @@ private function assertEncodedLength($encoded)
164165 return $ this ->encode ($ this ->jsonData );
165166 }
166167
168+ /**
169+ * Build Chromelogger JSON
170+ *
171+ * @return void
172+ */
173+ protected function buildJsonData ()
174+ {
175+ $ this ->jsonData ['rows ' ] = [];
176+ $ this ->processChannels ();
177+ if ($ this ->jsonData ['rows ' ]) {
178+ $ this ->wrapWithGroup ();
179+ }
180+ }
181+
167182 /**
168183 * Calculate header size
169184 *
170185 * @return int
171186 */
172187 protected function calcHeaderSize ()
173188 {
174- $ this ->processChannels ();
189+ $ this ->buildJsonData ();
175190 $ encoded = $ this ->encode ($ this ->jsonData );
176191 return \strlen (self ::HEADER_NAME . ': ' ) + \strlen ($ encoded );
177192 }
@@ -204,73 +219,6 @@ protected function getMaxLength()
204219 return \min ($ maxVals );
205220 }
206221
207- /**
208- * Process log entries for given channel
209- *
210- * @param Debug $instance Debug instance
211- *
212- * @return void
213- */
214- protected function processChannel (Debug $ instance )
215- {
216- $ channelKey = $ instance ->getCfg ('channelKey ' , Debug::CONFIG_DEBUG );
217- $ name = $ instance ->getCfg ('channelName ' , Debug::CONFIG_DEBUG );
218- $ this ->setChannelRegex ('#^ ' . \preg_quote ($ channelKey , '# ' ) . '(\.|$)# ' );
219-
220- $ include = $ this ->testChannelKeyMatch ($ channelKey , $ this ->cfg ['channels ' ])
221- && !$ this ->testChannelKeyMatch ($ channelKey , $ this ->cfg ['channelsExclude ' ]);
222-
223- if ($ include === false ) {
224- return ;
225- }
226-
227- if ($ instance === $ instance ->rootInstance ) {
228- $ name = $ this ->debug ->i18n ->trans ('channel.log ' );
229- }
230-
231- return $ this ->processLogEntryViaEvent (new LogEntry (
232- $ this ->debug ,
233- 'groupCollapsed ' ,
234- [$ name ]
235- ))
236- . $ this ->processAlerts ()
237- . $ this ->processSummary ()
238- . $ this ->processLog ()
239- . $ this ->processLogEntryViaEvent (new LogEntry (
240- $ this ->debug ,
241- 'groupEnd '
242- ));
243- }
244-
245- /**
246- * Process log entries grouped by top-level channels ("tabs")
247- *
248- * @return void
249- */
250- protected function processChannels ()
251- {
252- $ this ->jsonData ['rows ' ] = [];
253- $ channels = $ this ->debug ->getChannelsTop ();
254- foreach ($ channels as $ instance ) {
255- $ key = $ instance ->getCfg ('channelKey ' , Debug::CONFIG_DEBUG );
256- if (\in_array ($ key , $ this ->cfg ['channelsExclude ' ], true )) {
257- continue ;
258- }
259- if ($ instance ->getCfg ('output ' , Debug::CONFIG_DEBUG ) === false ) {
260- continue ;
261- }
262- $ this ->processChannel ($ instance );
263- }
264- $ heading = ['PHP ' , $ this ->getRequestMethodUri ()];
265- if (!$ this ->cfg ['group ' ]) {
266- // not wrapping in group, just prepend an info heading
267- \array_unshift ($ this ->jsonData ['rows ' ], [$ heading , null , 'info ' ]);
268- return ;
269- }
270- \array_unshift ($ this ->jsonData ['rows ' ], [$ heading , null , 'groupCollapsed ' ]);
271- \array_push ($ this ->jsonData ['rows ' ], [[], null , 'groupEnd ' ]);
272- }
273-
274222 /**
275223 * Attempt to remove log entries to get header length < max
276224 *
@@ -425,4 +373,21 @@ protected function translateJsonValues($json)
425373 $ json
426374 );
427375 }
376+
377+ /**
378+ * Wrap log in a group
379+ *
380+ * @return void
381+ */
382+ protected function wrapWithGroup ()
383+ {
384+ $ headingArgs = ['PHP ' , $ this ->getRequestMethodUri ()];
385+ if (!$ this ->cfg ['group ' ]) {
386+ // not wrapping in group -> prepend an info heading
387+ \array_unshift ($ this ->jsonData ['rows ' ], [$ headingArgs , null , 'info ' ]);
388+ return ;
389+ }
390+ \array_unshift ($ this ->jsonData ['rows ' ], [$ headingArgs , null , 'groupCollapsed ' ]);
391+ \array_push ($ this ->jsonData ['rows ' ], [[], null , 'groupEnd ' ]);
392+ }
428393}
0 commit comments