Skip to content

Commit a6af443

Browse files
committed
ChromeLogger, Firephp, Script, & ServerLog -default group cfg to false.. bucket each "tab" channel in own groupCollapsed
1 parent af71538 commit a6af443

12 files changed

Lines changed: 195 additions & 194 deletions

File tree

.editorconfig

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,13 @@ root = true
66
[*]
77
charset = utf-8
88
end_of_line = lf
9-
indent_style = space
10-
trim_trailing_whitespace = true
11-
12-
[*.js]
13-
indent_size = 2
14-
insert_final_newline = true
15-
16-
[*.json]
179
indent_size = 2
10+
indent_style = space
1811
insert_final_newline = true
12+
trim_trailing_whitespace = true
1913

2014
[*.md]
2115
trim_trailing_whitespace = false
2216

2317
[*.php]
2418
indent_size = 4
25-
insert_final_newline = true
26-
27-
[*.scss]
28-
indent_size = 2

src/Debug/Dump/Html/HtmlArray.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,8 @@ private function dumpArrayValues(array $array, $outputKeys, array $absKeys)
107107
'tagName' => null, // don't wrap it
108108
))
109109
)
110-
. '<span class="t_operator">=&gt;</span>'
111-
. $this->valDumper->dump($val)
112-
. '</li>' . "\n"
110+
. '<span class="t_operator">=&gt;</span>' . $this->valDumper->dump($val)
111+
. '</li>' . "\n"
113112
: "\t" . $this->valDumper->dump($val, array('tagName' => 'li')) . "\n";
114113
}
115114
return $html;

src/Debug/Route/AbstractRoute.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,70 @@ protected function getRequestMethodUri()
228228
. ' ' . $this->debug->redact((string) $this->debug->serverRequest->getUri());
229229
}
230230

231+
/**
232+
* Process log entries for given channel
233+
*
234+
* @param Debug $instance Debug instance
235+
*
236+
* @return string
237+
*/
238+
protected function processChannel(Debug $instance)
239+
{
240+
$channelKey = $instance->getCfg('channelKey', Debug::CONFIG_DEBUG);
241+
$name = $instance->getCfg('channelName', Debug::CONFIG_DEBUG);
242+
$this->setChannelRegex('#^' . \preg_quote($channelKey, '#') . '(\.|$)#');
243+
244+
$include = $this->testChannelKeyMatch($channelKey, $this->cfg['channels'])
245+
&& !$this->testChannelKeyMatch($channelKey, $this->cfg['channelsExclude']);
246+
247+
if ($include === false) {
248+
return '';
249+
}
250+
251+
if ($instance === $instance->rootInstance) {
252+
$name = $this->debug->i18n->trans('channel.log');
253+
}
254+
255+
return $this->processLogEntryViaEvent(new LogEntry(
256+
$this->debug,
257+
'groupCollapsed',
258+
[$name]
259+
))
260+
. $this->processAlerts()
261+
. $this->processSummary()
262+
. $this->processLog()
263+
. $this->processLogEntryViaEvent(new LogEntry(
264+
$this->debug,
265+
'groupEnd'
266+
));
267+
}
268+
269+
/**
270+
* Process log entries grouped by top-level channels ("tabs")
271+
*
272+
* Each channel will be wrapped in a groupCollapsed
273+
*
274+
* Call this via overridden `processLogEntries()` method
275+
*
276+
* @return string
277+
*/
278+
protected function processChannels()
279+
{
280+
$str = '';
281+
$channels = $this->debug->getChannelsTop();
282+
foreach ($channels as $instance) {
283+
$key = $instance->getCfg('channelKey', Debug::CONFIG_DEBUG);
284+
if (\in_array($key, $this->cfg['channelsExclude'], true)) {
285+
continue;
286+
}
287+
if ($instance->getCfg('output', Debug::CONFIG_DEBUG) === false) {
288+
continue;
289+
}
290+
$str .= $this->processChannel($instance);
291+
}
292+
return $str;
293+
}
294+
231295
/**
232296
* Publish Debug::EVENT_OUTPUT_LOG_ENTRY.
233297
* Return event['return'] if not empty

src/Debug/Route/ChromeLogger.php

Lines changed: 36 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/Debug/Route/Firephp.php

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Firephp extends AbstractRoute
3333
'events',
3434
'files',
3535
],
36+
'group' => false, // contain/wrap log in a group?
3637
'messageLimit' => 99999,
3738
);
3839

@@ -82,18 +83,17 @@ public function processLogEntries($event = null)
8283
$event['headers'][] = ['X-Wf-Protocol-1', 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2'];
8384
$event['headers'][] = ['X-Wf-1-Plugin-1', 'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/' . self::FIREPHP_PROTO_VER];
8485
$event['headers'][] = ['X-Wf-1-Structure-1', 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1'];
85-
$this->processLogEntryViaEvent(new LogEntry(
86-
$this->debug,
87-
'groupCollapsed',
88-
['PHP: ' . $this->getRequestMethodUri()]
89-
));
90-
$this->processAlerts();
91-
$this->processSummary();
92-
$this->processLog();
93-
$this->processLogEntryViaEvent(new LogEntry(
94-
$this->debug,
95-
'groupEnd'
96-
));
86+
if ($this->cfg['group']) {
87+
$this->processLogEntryViaEvent(new LogEntry(
88+
$this->debug,
89+
'groupCollapsed',
90+
['PHP: ' . $this->getRequestMethodUri()]
91+
));
92+
}
93+
$this->processChannels();
94+
if ($this->cfg['group']) {
95+
$this->processLogEntryViaEvent(new LogEntry($this->debug, 'groupEnd'));
96+
}
9797
$event['headers'][] = ['X-Wf-1-Index', $this->messageIndex];
9898
$this->data = array();
9999
$this->dumper->crateRaw = true;
@@ -210,7 +210,22 @@ private function methodTabular(LogEntry $logEntry)
210210
}
211211

212212
/**
213-
* set FirePHP log entry header(s)
213+
* {@inheritDoc}
214+
*/
215+
protected function processChannel(Debug $instance)
216+
{
217+
$messageIndexBefore = $this->messageIndex;
218+
parent::processChannel($instance);
219+
if ($this->messageIndex === $messageIndexBefore + 2) {
220+
// we only output the group start and end
221+
// remove the group start and end from the output
222+
$this->messageIndex -= 2;
223+
\array_splice($this->outputEvent['headers'], -2, 2);
224+
}
225+
}
226+
227+
/**
228+
* Set FirePHP log entry header(s)
214229
*
215230
* @param array $meta meta information
216231
* @param mixed $value value

0 commit comments

Comments
 (0)