From a290c5395b68d864a989428f476930c63e8b2f27 Mon Sep 17 00:00:00 2001 From: Florin Diaconu Date: Sun, 10 Dec 2023 19:52:22 +0200 Subject: [PATCH] added support for laravel.log general file --- config/laravel-log-reader.php | 4 ++-- src/LaravelLogReader.php | 26 ++++++++++++++------------ views/index.blade.php | 30 +++++++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/config/laravel-log-reader.php b/config/laravel-log-reader.php index 9cf3306..3ab4582 100644 --- a/config/laravel-log-reader.php +++ b/config/laravel-log-reader.php @@ -1,8 +1,8 @@ 'admin/api/log-reader', + 'api_route_path' => 'log/json', 'view_route_path' => 'admin/log-reader', 'admin_panel_path' => 'admin', 'middleware' => ['web', 'auth'] -]; \ No newline at end of file +]; diff --git a/src/LaravelLogReader.php b/src/LaravelLogReader.php index 7c9adb3..77514c4 100644 --- a/src/LaravelLogReader.php +++ b/src/LaravelLogReader.php @@ -8,10 +8,8 @@ class LaravelLogReader { - protected $final = []; protected $config = []; - public function __construct($config = []) { if (array_key_exists('date', $config)) { @@ -26,12 +24,12 @@ public function __construct($config = []) public function getLogFileDates() { $dates = []; - $files = glob(storage_path('logs/laravel-*.log')); + $files = glob(storage_path('logs/laravel*.log')); $files = array_reverse($files); foreach ($files as $path) { $fileName = basename($path); preg_match('/(?<=laravel-)(.*)(?=.log)/', $fileName, $dtMatch); - $date = $dtMatch[0]; + $date = $dtMatch[0] ?? null; array_push($dates, $date); } @@ -65,22 +63,26 @@ public function get() $pattern = "/^\[(?.*)\]\s(?\w+)\.(?\w+):(?.*)/m"; - $fileName = 'laravel-' . $configDate . '.log'; + $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), ]; } preg_match('/(?<=laravel-)(.*)(?=.log)/', $fileName, $dtMatch); - $date = $dtMatch[0]; + $date = $dtMatch[0] ?? null; $data = [ 'available_log_dates' => $availableDates, diff --git a/views/index.blade.php b/views/index.blade.php index a123d2a..542c00f 100644 --- a/views/index.blade.php +++ b/views/index.blade.php @@ -134,6 +134,10 @@ text-transform: uppercase; } + .angular-with-newlines { + white-space: pre-wrap; + } + @media screen and (max-width: 700px) { .top_content { flex-direction: column; @@ -311,11 +315,19 @@ - + @{{ log.timestamp }} - @{{log.env}} + @{{ log.env }} @{{ log.type }} - @{{ log.message }} + @{{ log.first_line }} + + +
@{{ log.message + }} +
+ @@ -340,6 +352,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;