Skip to content

Commit

Permalink
Make stack trace more readable (ARCANEDEV#141)
Browse files Browse the repository at this point in the history
* Make stack trace more readable

  * Make only stack row scrollable if it doesn't fit in the window size
  * Make trace's font lighter
  * Add ability to highlight words in trace. Make it configurable with line numbers by default

* Update code due to PR comments

* Fix scroll on hidden stack rows in windows
  • Loading branch information
mlanin authored and arcanedev-maroc committed May 18, 2017
1 parent 841749a commit 0c8a8c9
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 4 deletions.
9 changes: 9 additions & 0 deletions config/log-viewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,13 @@
'debug' => '#90CAF9',
],
],

/* ------------------------------------------------------------------------------------------------
| Strings to highlight in stack trace
| ------------------------------------------------------------------------------------------------
*/
'highlight' => [
'^#\d+',
'^Stack trace:',
],
];
14 changes: 11 additions & 3 deletions resources/views/_template/style.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions resources/views/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '<strong>$1</strong>');
$this.html(html);
});
@endunless
});
</script>
@endsection
9 changes: 9 additions & 0 deletions src/Contracts/Utilities/LogStyler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []);
}
2 changes: 1 addition & 1 deletion src/Entities/LogEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function icon()
*/
public function stack()
{
return nl2br(htmlentities($this->stack), false);
return trim(htmlentities($this->stack));
}

/* ------------------------------------------------------------------------------------------------
Expand Down
12 changes: 12 additions & 0 deletions src/Utilities/LogStyler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
11 changes: 11 additions & 0 deletions tests/Utilities/LogStylerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 0c8a8c9

Please sign in to comment.