From 17b2a2547164d8ea43966abeb5b297b89d845fdf Mon Sep 17 00:00:00 2001 From: Ekaterina Date: Wed, 30 Sep 2020 21:51:05 +0200 Subject: [PATCH] Fixes #14 - if there's '\n' is present in message, shows the first line and adds button 'Show full stack' + small js fix for filter by type --- src/LaravelLogReader.php | 22 ++++++++++++---------- views/index.blade.php | 30 +++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/LaravelLogReader.php b/src/LaravelLogReader.php index 7c9adb3..72d696e 100644 --- a/src/LaravelLogReader.php +++ b/src/LaravelLogReader.php @@ -4,11 +4,11 @@ * Date: 25/01/2020 * Website: laravelarticle.com */ + namespace Haruncpi\LaravelLogReader; class LaravelLogReader { - protected $final = []; protected $config = []; @@ -62,20 +62,22 @@ public function get() ]); } - - $pattern = "/^\[(?.*)\]\s(?\w+)\.(?\w+):(?.*)/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('/\[(?.*)\]\s(?\w+)\.(?\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), ]; } diff --git a/views/index.blade.php b/views/index.blade.php index 00a0bdd..568f1da 100644 --- a/views/index.blade.php +++ b/views/index.blade.php @@ -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; @@ -306,11 +310,19 @@ - + @{{ log.timestamp }} - @{{log.env}} + @{{ log.env }} @{{ log.type }} - @{{ log.message }} + @{{ log.first_line }} + + +
@{{ log.message + }} +
+ @@ -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;