Skip to content

Commit 211f4c2

Browse files
author
Greg Bowler
committed
feature: debug output
for #447
1 parent 694fee5 commit 211f4c2

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

composer.lock

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Middleware/Lifecycle.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,8 @@ public function finish(
112112
}
113113

114114
if(strlen($buffer) > 0) {
115-
if(str_contains($buffer, "\n")) {
116-
$buffer = "\n$buffer";
117-
}
118-
Log::debug("Logic output: $buffer");
115+
$newLine = str_contains($buffer, "\n") ? "\n" : "";
116+
Log::debug("Logic output: {$newLine}{$buffer}");
119117
}
120118

121119
$renderBufferSize = $appConfig->getInt("render_buffer_size");
@@ -128,6 +126,18 @@ public function finish(
128126
flush();
129127
}
130128

129+
if(strlen($buffer) > 0) {
130+
$buffer = str_replace("</script", "<\\/script", $buffer);
131+
$js = <<<JS
132+
<script id="webengine-debug">
133+
console.group("%cphp.gt/webengine", "display: inline-block; padding: 0.5em 1em; background: #26a5e3; color: white; cursor: pointer");
134+
console.info(`$buffer`);
135+
console.groupEnd();
136+
</script>
137+
JS;
138+
echo $js;
139+
}
140+
131141
// The very last thing that's done before the script ends is to stop the Timer,
132142
// so we know exactly how long the request-response lifecycle has taken.
133143
$this->timer->stop();

0 commit comments

Comments
 (0)