From 10ed3d014ef68742808bbb46a908b2890d0abf95 Mon Sep 17 00:00:00 2001 From: rap2hpoutre Date: Sun, 23 Nov 2014 15:10:14 +0100 Subject: [PATCH] First commit --- .gitignore | 6 ++ composer.json | 24 ++++++++ phpunit.xml | 18 ++++++ .../LaravelLogViewer/LaravelLogViewer.php | 56 +++++++++++++++++ .../LaravelLogViewerServiceProvider.php | 44 ++++++++++++++ src/config/.gitkeep | 0 src/controllers/.gitkeep | 0 src/controllers/LogViewerController.php | 16 +++++ src/lang/.gitkeep | 0 src/views/.gitkeep | 0 src/views/log.blade.php | 60 +++++++++++++++++++ tests/.gitkeep | 0 12 files changed, 224 insertions(+) create mode 100644 .gitignore create mode 100644 composer.json create mode 100644 phpunit.xml create mode 100644 src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php create mode 100644 src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewerServiceProvider.php create mode 100644 src/config/.gitkeep create mode 100644 src/controllers/.gitkeep create mode 100644 src/controllers/LogViewerController.php create mode 100644 src/lang/.gitkeep create mode 100644 src/views/.gitkeep create mode 100644 src/views/log.blade.php create mode 100644 tests/.gitkeep diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..87884ef --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/vendor +composer.phar +composer.lock +laravel +.DS_Store +.idea \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..9537b63 --- /dev/null +++ b/composer.json @@ -0,0 +1,24 @@ +{ + "name": "rap2hpoutre/laravel-log-viewer", + "description": "", + "authors": [ + { + "name": "rap2hpoutre", + "email": "raphael@ornikar.com" + } + ], + "require": { + "php": ">=5.4.0", + "illuminate/support": "4.2.*" + }, + "autoload": { + "classmap": [ + "src/migrations", + "src/controllers" + ], + "psr-0": { + "Rap2hpoutre\\LaravelLogViewer\\": "src/" + } + }, + "minimum-stability": "stable" +} diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..3347b75 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,18 @@ + + + + + ./tests/ + + + diff --git a/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php b/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php new file mode 100644 index 0000000..93e6f50 --- /dev/null +++ b/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php @@ -0,0 +1,56 @@ +getConstants(); + + $pattern = '/\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\].*/'; + + $log_file = storage_path() . '/logs/laravel.log'; + + $file = File::get($log_file); + + preg_match_all($pattern, $file, $headings); + + $log_data = preg_split($pattern, $file); + + if ($log_data[0] < 1) { + $trash = array_shift($log_data); + unset($trash); + } + + foreach ($headings as $h) { + for ($i=0, $j = count($h); $i < $j; $i++) { + foreach ($log_levels as $ll) { + if (strpos(strtolower($h[$i]), strtolower('.'.$ll))) { + + $level = strtoupper($ll); + + preg_match('/^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\].*?\.' . $level . ': (.*?)( in .*?:[0-9]+)?$/', $h[$i], $current); + + $log[] = array( + 'level' => $ll, + 'date' => $current[1], + 'text' => $current[2], + 'in_file' => isset($current[3]) ? $current[3] : null, + 'stack' => $log_data[$i] + ); + } + } + } + } + + $log = array_reverse($log); + return $log; + } +} \ No newline at end of file diff --git a/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewerServiceProvider.php b/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewerServiceProvider.php new file mode 100644 index 0000000..cbd0d4f --- /dev/null +++ b/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewerServiceProvider.php @@ -0,0 +1,44 @@ +package('rap2hpoutre/laravel-log-viewer', null, __DIR__); + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + // + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return array(); + } + +} diff --git a/src/config/.gitkeep b/src/config/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/controllers/.gitkeep b/src/controllers/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/controllers/LogViewerController.php b/src/controllers/LogViewerController.php new file mode 100644 index 0000000..9cb551f --- /dev/null +++ b/src/controllers/LogViewerController.php @@ -0,0 +1,16 @@ + $logs]); + } + +} diff --git a/src/lang/.gitkeep b/src/lang/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/views/.gitkeep b/src/views/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/views/log.blade.php b/src/views/log.blade.php new file mode 100644 index 0000000..f203224 --- /dev/null +++ b/src/views/log.blade.php @@ -0,0 +1,60 @@ + + + + + + + Laravel log viewer + + + + + + + + + +
+
+ +
+
+
+ + + + + + + + + + @foreach($logs as $log) + + + + + + @endforeach + +
LevelDateContent
{{{$log['level']}}}{{{$log['date']}}} + {{{$log['text']}}} + @if (isset($log['in_file'])) +
{{{$log['in_file']}}} + @endif +
+
+
+
+
+
+ + + + + \ No newline at end of file diff --git a/tests/.gitkeep b/tests/.gitkeep new file mode 100644 index 0000000..e69de29