Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #14 - Showing the full stack message #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/LaravelLogReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* Date: 25/01/2020
* Website: laravelarticle.com
*/

namespace Haruncpi\LaravelLogReader;

class LaravelLogReader
{
protected $final = [];
Copy link
Author

@Katenkka Katenkka Oct 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was not used anywhere, hence removed

protected $config = [];


Expand Down Expand Up @@ -62,20 +62,22 @@ public function get()
]);
}


$pattern = "/^\[(?<date>.*)\]\s(?<env>\w+)\.(?<type>\w+):(?<message>.*)/m";

$fileName = 'laravel-' . $configDate . '.log';
$content = file_get_contents(storage_path('logs/' . $fileName));
preg_match_all($pattern, $content, $matches, PREG_SET_ORDER, 0);

// splitting by regexp in order to get the whole message between 2 log entries
$chars = preg_split('/\[(?<date>.*)\]\s(?<env>\w+)\.(?<type>\w+):/i', $content, -1,
PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
// chunking - every chung will contain all needed data
$matches = array_chunk($chars, 4, false);

$logs = [];
foreach ($matches as $match) {
foreach ($matches as [$date, $env, $type, $message]) {
$logs[] = [
'timestamp' => $match['date'],
'env' => $match['env'],
'type' => $match['type'],
'message' => trim($match['message'])
'timestamp' => $date,
'env' => $env,
'type' => $type,
'message' => trim($message),
];
}

Expand Down
30 changes: 27 additions & 3 deletions views/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@
text-transform: uppercase;
}

.angular-with-newlines {
white-space: pre-wrap;
}

@media screen and (max-width: 700px) {
.top_content {
flex-direction: column;
Expand Down Expand Up @@ -306,11 +310,19 @@
</tr>
</thead>

<tr ng-repeat="log in data.logs |filter: selectedType track by $index">
<tr ng-repeat="log in data.logs | filter: {type:selectedType} track by $index">
<td>@{{ log.timestamp }}</td>
<td>@{{log.env}}</td>
<td>@{{ log.env }}</td>
<td><span class="badge @{{ log.type.toLowerCase() }}">@{{ log.type }}</span></td>
<td>@{{ log.message }}</td>
<td>@{{ log.first_line }}
<input type="button" value="Show Full Stack" ng-hide="!log.message || log.showStackTrace"
ng-click="log.showStackTrace = true"/>
<input type="button" value="Hide Full Stack" ng-show="log.message && log.showStackTrace"
ng-click="log.showStackTrace = false"/>
<div class="angular-with-newlines" ng-show="log.message && log.showStackTrace">@{{ log.message
}}
</div>
</td>
</tr>
</table>
</div>
Expand All @@ -335,6 +347,18 @@

$http.get(url)
.success(function (data) {
data.data.logs.forEach(function (el) {
el.showStackTrace = false;
var firstBreakIndex = el.message.indexOf('\n');
if (firstBreakIndex === -1) {
el.first_line = el.message;
el.message = undefined;
} else {
el.first_line = el.message.substr(0, firstBreakIndex + 1);
el.message = el.message.substr(firstBreakIndex + 1);
}
});

$scope.response = data;
$scope.data = data.data;
originalData = data.data;
Expand Down