diff --git a/config/log-viewer.php b/config/log-viewer.php index d2450f88..c0f9a970 100644 --- a/config/log-viewer.php +++ b/config/log-viewer.php @@ -113,4 +113,13 @@ 'debug' => '#90CAF9', ], ], + + /* ------------------------------------------------------------------------------------------------ + | Strings to highlight in stack trace + | ------------------------------------------------------------------------------------------------ + */ + 'highlight' => [ + '^#\d+', + '^Stack trace:', + ], ]; diff --git a/resources/views/_template/style.blade.php b/resources/views/_template/style.blade.php index 5221d477..191e865d 100644 --- a/resources/views/_template/style.blade.php +++ b/resources/views/_template/style.blade.php @@ -83,15 +83,23 @@ .table-condensed > thead > tr > td.stack { padding: 0; border-top: none; + background-color: #F6F6F6; + border-top: 1px solid #D1D1D1; + max-width: 0; + overflow-x: auto; + } + + .table-condensed > tbody > tr > td > p { + margin: 0; } .stack-content { padding: 8px; - background-color: #F6F6F6; - border-top: 1px solid #D1D1D1; color: #AE0E0E; - font-family: consolas,sans-serif; + font-family: consolas, Menlo, Courier, monospace; font-size: 12px; + font-weight: 400; + white-space: pre-line; } .info-box.level { diff --git a/resources/views/show.blade.php b/resources/views/show.blade.php index f1567686..68125357 100644 --- a/resources/views/show.blade.php +++ b/resources/views/show.blade.php @@ -193,6 +193,16 @@ return false; }); + + @unless (empty(log_styler()->toHighlight())) + $('.stack-content').each(function() { + var $this = $(this); + var html = $this.html().trim() + .replace(/({!! join(log_styler()->toHighlight(), '|') !!})/gm, '$1'); + + $this.html(html); + }); + @endunless }); @endsection diff --git a/src/Contracts/Utilities/LogStyler.php b/src/Contracts/Utilities/LogStyler.php index d86d4dc9..ccf7d2af 100644 --- a/src/Contracts/Utilities/LogStyler.php +++ b/src/Contracts/Utilities/LogStyler.php @@ -31,4 +31,13 @@ public function icon($level, $default = null); * @return string */ public function color($level, $default = null); + + /** + * Get strings to highlight. + * + * @param array $default + * + * @return string + */ + public function toHighlight(array $default = []); } diff --git a/src/Entities/LogEntry.php b/src/Entities/LogEntry.php index d497606e..4656f32c 100644 --- a/src/Entities/LogEntry.php +++ b/src/Entities/LogEntry.php @@ -170,7 +170,7 @@ public function icon() */ public function stack() { - return nl2br(htmlentities($this->stack), false); + return trim(htmlentities($this->stack)); } /* ------------------------------------------------------------------------------------------------ diff --git a/src/Utilities/LogStyler.php b/src/Utilities/LogStyler.php index 555b8adc..9c6206ae 100644 --- a/src/Utilities/LogStyler.php +++ b/src/Utilities/LogStyler.php @@ -82,4 +82,16 @@ public function color($level, $default = null) { return $this->get("colors.levels.$level", $default); } + + /** + * Get strings to highlight. + * + * @param array $default + * + * @return string + */ + public function toHighlight(array $default = []) + { + return $this->get("highlight", $default); + } } diff --git a/tests/Utilities/LogStylerTest.php b/tests/Utilities/LogStylerTest.php index 5d239d75..0bb029b2 100644 --- a/tests/Utilities/LogStylerTest.php +++ b/tests/Utilities/LogStylerTest.php @@ -101,4 +101,15 @@ public function it_can_use_helper_get_color() $this->assertHexColor(log_styler()->color($level)); } } + + /** @test */ + public function it_can_get_string_to_highlight() + { + $expected = [ + '^#\d+', + '^Stack trace:', + ]; + + $this->assertSame($expected, $this->styler->toHighlight()); + } }