Repository: rap2hpoutre/laravel-log-viewer Branch: master Commit: ab85d5d88de7 Files: 15 Total size: 43.6 KB Directory structure: gitextract_pf84q1ng/ ├── .github/ │ └── workflows/ │ └── run-tests.yml ├── .gitignore ├── LICENSE ├── README.md ├── composer.json ├── phpunit.xml ├── src/ │ ├── Rap2hpoutre/ │ │ └── LaravelLogViewer/ │ │ ├── LaravelLogViewer.php │ │ ├── LaravelLogViewerServiceProvider.php │ │ ├── Level.php │ │ └── Pattern.php │ ├── config/ │ │ └── logviewer.php │ ├── controllers/ │ │ └── LogViewerController.php │ └── views/ │ └── log.blade.php └── tests/ ├── LaravelLogViewerTest.php └── laravel.log ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/workflows/run-tests.yml ================================================ name: Tests on: push: pull_request: jobs: tests: strategy: fail-fast: true matrix: php: ["7.2", "7.4", "8.0", "8.1", "8.2", "8.3", "8.4"] laravel: ["^6.0", "^7.0", "^8.0", "^9.0", "^10.0", "^11.0", "^12.0"] exclude: - php: "8.0" laravel: "^10.0" - php: "7.4" laravel: "^10.0" - php: "7.2" laravel: "^10.0" - php: "7.4" laravel: "^9.0" - php: "7.2" laravel: "^9.0" - php: "8.4" laravel: "^8.0" - php: "8.3" laravel: "^8.0" - php: "8.2" laravel: "^8.0" - php: "7.2" laravel: "^8.0" - php: "8.4" laravel: "^7.0" - php: "8.3" laravel: "^7.0" - php: "8.2" laravel: "^7.0" - php: "8.1" laravel: "^7.0" - php: "8.4" laravel: "^6.0" - php: "8.3" laravel: "^6.0" - php: "8.2" laravel: "^6.0" - php: "8.1" laravel: "^6.0" - php: "7.2" laravel: "^11.0" - php: "7.4" laravel: "^11.0" - php: "8.0" laravel: "^11.0" - php: "8.1" laravel: "^11.0" - php: "7.2" laravel: "^12.0" - php: "7.4" laravel: "^12.0" - php: "8.0" laravel: "^12.0" - php: "8.1" laravel: "^12.0" name: "PHP${{ matrix.php }} - Laravel${{ matrix.laravel }}" runs-on: "ubuntu-latest" steps: - name: "Checkout code" uses: "actions/checkout@v3" - name: "Setup PHP" uses: "shivammathur/setup-php@v2" with: php-version: "${{ matrix.php }}" extensions: "dom, curl, libxml, mbstring, zip, fileinfo" tools: "composer:v2" coverage: "none" - name: "Check Composer configuration" run: "composer validate --strict" - name: "Install dependencies from composer.json" run: "composer update --with='laravel/framework:${{ matrix.laravel }}' --no-interaction --no-progress" - name: "Check PSR-4 mapping" run: "composer dump-autoload --optimize --strict-psr" - name: "Execute unit tests" run: "vendor/bin/phpunit" ================================================ FILE: .gitignore ================================================ /vendor composer.lock /.idea /build .phpunit.result.cache ================================================ FILE: LICENSE ================================================ The MIT License (MIT) Copyright (c) 2014-present rap2hpoutre Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ Laravel log viewer ================== [![Packagist](https://img.shields.io/packagist/v/rap2hpoutre/laravel-log-viewer.svg)](https://packagist.org/packages/rap2hpoutre/laravel-log-viewer) [![Packagist](https://img.shields.io/packagist/l/rap2hpoutre/laravel-log-viewer.svg)](https://packagist.org/packages/rap2hpoutre/laravel-log-viewer) [![Packagist](https://img.shields.io/packagist/dm/rap2hpoutre/laravel-log-viewer.svg)](https://packagist.org/packages/rap2hpoutre/laravel-log-viewer) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/rap2hpoutre/laravel-log-viewer/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/rap2hpoutre/laravel-log-viewer/?branch=master) [![Author](https://img.shields.io/badge/author-@rap2h-blue.svg)](https://twitter.com/rap2h) ## TL;DR Log Viewer for Laravel 6, 7, 8, 9, 10, 11 & 12 and Lumen. **Install with composer, create a route to `LogViewerController`**. No public assets, no vendor routes, works with and/or without log rotate. Inspired by Micheal Mand's [Laravel 4 log viewer](https://github.com/mikemand/logviewer) (works only with laravel 4.1) ## What ? Small log viewer for laravel. Looks like this: ![capture d ecran 2014-12-01 a 10 37 18](https://cloud.githubusercontent.com/assets/1575946/5243642/8a00b83a-7946-11e4-8bad-5c705f328bcc.png) ## Install (Laravel) Install via composer ```bash composer require rap2hpoutre/laravel-log-viewer ``` Add Service Provider to `config/app.php` in `providers` section ```php Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider::class, ``` Add a route in your web routes file: ```php Route::get('logs', [\Rap2hpoutre\LaravelLogViewer\LogViewerController::class, 'index']); ``` Go to `http://myapp/logs` or some other route ### Install (Lumen) Install via composer ```bash composer require rap2hpoutre/laravel-log-viewer ``` Add the following in `bootstrap/app.php`: ```php $app->register(\Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider::class); ``` Explicitly set the namespace in `app/Http/routes.php`: ```php $router->group(['namespace' => '\Rap2hpoutre\LaravelLogViewer'], function() use ($router) { $router->get('logs', 'LogViewerController@index'); }); ``` ## Advanced usage ### Customize view Publish `log.blade.php` into `/resources/views/vendor/laravel-log-viewer/` for view customization: ```bash php artisan vendor:publish \ --provider="Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider" \ --tag=views ``` ### Edit configuration Publish `logviewer.php` configuration file into `/config/` for configuration customization: ```bash php artisan vendor:publish \ --provider="Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider" ``` ### Troubleshooting If you got a `InvalidArgumentException in FileViewFinder.php` error, it may be a problem with config caching. Double check installation, then run `php artisan config:clear`. ================================================ FILE: composer.json ================================================ { "name": "rap2hpoutre/laravel-log-viewer", "description": "A Laravel log reader", "license": "MIT", "keywords": [ "log", "log-reader", "log-viewer", "logging", "laravel", "lumen" ], "type": "laravel-package", "authors": [ { "name": "rap2hpoutre", "email": "raphaelht@gmail.com" } ], "require": { "php": "^7.2|^8.0", "illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0" }, "require-dev": { "phpunit/phpunit": "^7||^8.4|^9.3.3|^10.1|^11.0", "orchestra/testbench": "^4.0|^5.0|^6.0|^7.0|^8.0|^9.0|^10.0" }, "autoload": { "classmap": [ "src/controllers" ], "psr-0": { "Rap2hpoutre\\LaravelLogViewer\\": "src/" } }, "autoload-dev": { "psr-4": { "Rap2hpoutre\\LaravelLogViewer\\Tests\\": "tests/" } }, "extra": { "laravel": { "providers": [ "Rap2hpoutre\\LaravelLogViewer\\LaravelLogViewerServiceProvider" ] } }, "minimum-stability": "stable" } ================================================ FILE: phpunit.xml ================================================ tests/ ================================================ FILE: src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php ================================================ level = new Level(); $this->pattern = new Pattern(); $this->storage_path = function_exists('config') ? config('logviewer.storage_path', storage_path('logs')) : storage_path('logs'); } /** * @param string $folder */ public function setFolder($folder) { if (app('files')->exists($folder)) { $this->folder = $folder; } else if (is_array($this->storage_path)) { foreach ($this->storage_path as $value) { $logsPath = $value . '/' . $folder; if (app('files')->exists($logsPath)) { $this->folder = $folder; break; } } } else { $logsPath = $this->storage_path . '/' . $folder; if (app('files')->exists($logsPath)) { $this->folder = $folder; } } } /** * @param string $file * @throws \Exception */ public function setFile($file) { $file = $this->pathToLogFile($file); if (app('files')->exists($file)) { $this->file = $file; } } /** * @param string $file * @return string * @throws \Exception */ public function pathToLogFile($file) { if (app('files')->exists($file)) { // try the absolute path return $file; } if (is_array($this->storage_path)) { foreach ($this->storage_path as $folder) { if (app('files')->exists($folder . '/' . $file)) { // try the absolute path $file = $folder . '/' . $file; break; } } return $file; } $logsPath = $this->storage_path; $logsPath .= ($this->folder) ? '/' . $this->folder : ''; $file = $logsPath . '/' . $file; // check if requested file is really in the logs directory if (dirname($file) !== $logsPath) { throw new \Exception('No such log file: ' . $file); } return $file; } /** * @return string */ public function getFolderName() { return $this->folder; } /** * @return string */ public function getFileName() { return basename($this->file); } /** * @return array */ public function all() { $log = array(); if (!$this->file) { $log_file = (!$this->folder) ? $this->getFiles() : $this->getFolderFiles(); if (!count($log_file)) { return []; } $this->file = $log_file[0]; } $max_file_size = function_exists('config') ? config('logviewer.max_file_size', self::MAX_FILE_SIZE) : self::MAX_FILE_SIZE; if (app('files')->size($this->file) > $max_file_size) { return null; } if (!is_readable($this->file)) { return [[ 'context' => '', 'level' => '', 'date' => null, 'text' => 'Log file "' . $this->file . '" not readable', 'stack' => '', ]]; } $file = app('files')->get($this->file); preg_match_all($this->pattern->getPattern('logs'), $file, $headings); if (!is_array($headings)) { return $log; } $log_data = preg_split($this->pattern->getPattern('logs'), $file); if ($log_data[0] < 1) { array_shift($log_data); } foreach ($headings as $h) { for ($i = 0, $j = count($h); $i < $j; $i++) { foreach ($this->level->all() as $level) { if (strpos(strtolower($h[$i]), '.' . $level) || strpos(strtolower($h[$i]), $level . ':')) { preg_match($this->pattern->getPattern('current_log', 0) . $level . $this->pattern->getPattern('current_log', 1), $h[$i], $current); if (!isset($current[4])) { continue; } $log[] = array( 'context' => $current[3], 'level' => $level, 'folder' => $this->folder, 'level_class' => $this->level->cssClass($level), 'level_img' => $this->level->img($level), 'date' => $current[1], 'text' => $current[4], 'in_file' => isset($current[5]) ? $current[5] : null, 'stack' => preg_replace("/^\n*/", '', $log_data[$i]) ); } } } } if (empty($log)) { $lines = explode(PHP_EOL, $file); $log = []; foreach ($lines as $key => $line) { $log[] = [ 'context' => '', 'level' => '', 'folder' => '', 'level_class' => '', 'level_img' => '', 'date' => $key + 1, 'text' => $line, 'in_file' => null, 'stack' => '', ]; } } return array_reverse($log); } /**Creates a multidimensional array * of subdirectories and files * * @param null $path * * @return array */ public function foldersAndFiles($path = null) { $contents = array(); $dir = $path ? $path : $this->storage_path; foreach (scandir($dir) as $node) { if ($node == '.' || $node == '..') continue; $path = $dir . '\\' . $node; if (is_dir($path)) { $contents[$path] = $this->foldersAndFiles($path); } else { $contents[] = $path; } } return $contents; } /**Returns an array of * all subdirectories of specified directory * * @param string $folder * * @return array */ public function getFolders($folder = '') { $folders = []; $listObject = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator($this->storage_path . '/' . $folder, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST ); foreach ($listObject as $fileinfo) { if ($fileinfo->isDir()) $folders[] = $fileinfo->getRealPath(); } return $folders; } /** * @param bool $basename * @return array */ public function getFolderFiles($basename = false) { return $this->getFiles($basename, $this->folder); } /** * @param bool $basename * @param string $folder * @return array */ public function getFiles($basename = false, $folder = '') { $files = []; $pattern = function_exists('config') ? config('logviewer.pattern', '*.log') : '*.log'; $fullPath = $this->storage_path . '/' . $folder; $listObject = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator($fullPath, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST ); foreach ($listObject as $fileinfo) { if (!$fileinfo->isDir() && strtolower(pathinfo($fileinfo->getRealPath(), PATHINFO_EXTENSION)) == explode('.', $pattern)[1]) $files[] = $basename ? basename($fileinfo->getRealPath()) : $fileinfo->getRealPath(); } arsort($files); return array_values($files); } /** * @return string */ public function getStoragePath() { return $this->storage_path; } /** * @param $path * * @return void */ public function setStoragePath($path) { $this->storage_path = $path; } public static function directoryTreeStructure($storage_path, array $array) { foreach ($array as $k => $v) { if (is_dir($k)) { $exploded = explode("\\", $k); $show = last($exploded); echo '
       ' . $show . '
'; if (is_array($v)) { self::directoryTreeStructure($storage_path, $v); } } else { $exploded = explode("\\", $v); $show2 = last($exploded); $folder = str_replace($storage_path, "", rtrim(str_replace($show2, "", $v), "\\")); $file = $v; echo '
       ' . $show2 . '
'; } } return; } } ================================================ FILE: src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewerServiceProvider.php ================================================ package('rap2hpoutre/laravel-log-viewer', 'laravel-log-viewer', __DIR__.'/../../'); } if (method_exists($this, 'loadViewsFrom')) { $this->loadViewsFrom(__DIR__.'/../../views', 'laravel-log-viewer'); } if (method_exists($this, 'publishes')) { $this->publishes([ __DIR__.'/../../views' => base_path('/resources/views/vendor/laravel-log-viewer'), ], 'views'); $this->publishes([ __DIR__.'/../../config/logviewer.php' => $this->config_path('logviewer.php'), ]); } } /** * Register the service provider. * * @return void */ public function register() { // } /** * Get the configuration path. * * @param string $path * @return string */ private function config_path($path = '') { return function_exists('config_path') ? config_path($path) : app()->basePath().DIRECTORY_SEPARATOR.'config'.($path ? DIRECTORY_SEPARATOR.$path : $path); } } ================================================ FILE: src/Rap2hpoutre/LaravelLogViewer/Level.php ================================================ */ private $levelsClasses = [ 'debug' => 'info', 'info' => 'info', 'notice' => 'info', 'warning' => 'warning', 'error' => 'danger', 'critical' => 'danger', 'alert' => 'danger', 'emergency' => 'danger', 'processed' => 'info', 'failed' => 'warning', ]; /** * @var array */ private $icons = [ 'debug' => 'info-circle', 'info' => 'info-circle', 'notice' => 'info-circle', 'warning' => 'exclamation-triangle', 'error' => 'exclamation-triangle', 'critical' => 'exclamation-triangle', 'alert' => 'exclamation-triangle', 'emergency' => 'exclamation-triangle', 'processed' => 'info-circle', 'failed' => 'exclamation-triangle' ]; /** * @return string[] */ public function all() { return array_keys($this->icons); } /** * @param string $level * @return string */ public function img($level) { return $this->icons[$level]; } /** * @param string $level * @return string */ public function cssClass($level) { return $this->levelsClasses[$level]; } } ================================================ FILE: src/Rap2hpoutre/LaravelLogViewer/Pattern.php ================================================ */ private $patterns = [ 'logs' => '/\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}([\+-]\d{4})?\].*/', 'current_log' => [ '/^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}([\+-]\d{4})?)\](?:.*?(\w+)\.|.*?)', ': (.*?)( in .*?:[0-9]+)?$/i' ], 'files' => '/\{.*?\,.*?\}/i', ]; /** * @return string[] */ public function all() { return array_keys($this->patterns); } /** * @param string $pattern * @param null|string $position * @return string pattern */ public function getPattern($pattern, $position = null) { if ($position !== null) { return $this->patterns[$pattern][$position]; } return $this->patterns[$pattern]; } } ================================================ FILE: src/config/logviewer.php ================================================ 52428800, // size in Byte 'pattern' => env('LOGVIEWER_PATTERN', '*.log'), 'storage_path' => env('LOGVIEWER_STORAGE_PATH', storage_path('logs')), ]; ================================================ FILE: src/controllers/LogViewerController.php ================================================ log_viewer = new LaravelLogViewer(); $this->request = app('request'); } /** * @return array|mixed * @throws \Exception */ public function index() { $folderFiles = []; if ($this->request->input('f')) { $this->log_viewer->setFolder(Crypt::decrypt($this->request->input('f'))); $folderFiles = $this->log_viewer->getFolderFiles(true); } if ($this->request->input('l')) { $this->log_viewer->setFile(Crypt::decrypt($this->request->input('l'))); } if ($early_return = $this->earlyReturn()) { return $early_return; } $data = [ 'logs' => $this->log_viewer->all(), 'folders' => $this->log_viewer->getFolders(), 'current_folder' => $this->log_viewer->getFolderName(), 'folder_files' => $folderFiles, 'files' => $this->log_viewer->getFiles(true), 'current_file' => $this->log_viewer->getFileName(), 'standardFormat' => true, 'structure' => $this->log_viewer->foldersAndFiles(), 'storage_path' => $this->log_viewer->getStoragePath(), ]; if ($this->request->wantsJson()) { return $data; } if (is_array($data['logs']) && count($data['logs']) > 0) { $firstLog = reset($data['logs']); if ($firstLog) { if (!$firstLog['context'] && !$firstLog['level']) { $data['standardFormat'] = false; } } } return app('view')->make($this->view_log, $data); } /** * @return bool|mixed * @throws \Exception */ private function earlyReturn() { if ($this->request->input('f')) { $this->log_viewer->setFolder(Crypt::decrypt($this->request->input('f'))); } if ($this->request->input('dl')) { return $this->download($this->pathFromInput('dl')); } elseif ($this->request->has('clean')) { app('files')->put($this->pathFromInput('clean'), ''); return $this->redirect(url()->previous()); } elseif ($this->request->has('del')) { app('files')->delete($this->pathFromInput('del')); return $this->redirect($this->request->url()); } elseif ($this->request->has('delall')) { $files = ($this->log_viewer->getFolderName()) ? $this->log_viewer->getFolderFiles(true) : $this->log_viewer->getFiles(true); foreach ($files as $file) { app('files')->delete($this->log_viewer->pathToLogFile($file)); } return $this->redirect($this->request->url()); } return false; } /** * @param string $input_string * @return string * @throws \Exception */ private function pathFromInput($input_string) { return $this->log_viewer->pathToLogFile(Crypt::decrypt($this->request->input($input_string))); } /** * @param $to * @return mixed */ private function redirect($to) { if (function_exists('redirect')) { return redirect($to); } return app('redirect')->to($to); } /** * @param string $data * @return mixed */ private function download($data) { if (function_exists('response')) { return response()->download($data); } // For laravel 4.2 return app('\Illuminate\Support\Facades\Response')->download($data); } } ================================================ FILE: src/views/log.blade.php ================================================ Laravel log viewer
@if ($logs === null)
Log file >50M, please download it.
@else @if ($standardFormat) @else @endif @foreach($logs as $key => $log) @if ($standardFormat) @endif @endforeach
Level Context DateLine numberContent
  {{$log['level']}} {{$log['context']}}{{{$log['date']}}} @if ($log['stack']) @endif {{{$log['text']}}} @if (isset($log['in_file']))
{{{$log['in_file']}}} @endif @if ($log['stack']) @endif
@endif
@if($current_file) Download file - Clean file - Delete file @if(count($files) > 1) - Delete all files @endif @endif
================================================ FILE: tests/LaravelLogViewerTest.php ================================================ set('app.key', 'XP0aw2Dkrk22p0JoAOzulOl8XkUxlvkO'); // Copy "laravel.log" file to the orchestra package. if (!file_exists(storage_path('logs/laravel.log'))) { copy(__DIR__ . '/laravel.log', storage_path('logs/laravel.log')); } } /** * @throws \Exception */ public function testSetFile() { $laravel_log_viewer = new LaravelLogViewer(); $laravel_log_viewer->setFile("laravel.log"); $this->assertEquals("laravel.log", $laravel_log_viewer->getFileName()); } public function testSetFolderWithCorrectPath() { $laravel_log_viewer = new LaravelLogViewer(); $laravel_log_viewer->setFolder(basename((__DIR__))); $this->assertEquals("tests", $laravel_log_viewer->getFolderName()); } public function testSetFolderWithArrayStoragePath() { $path = __DIR__; $laravel_log_viewer = new LaravelLogViewer(); $laravel_log_viewer->setStoragePath([$path]); if(!File::exists("$path/samuel")) File::makeDirectory("$path/samuel"); $laravel_log_viewer->setFolder('samuel'); $this->assertEquals("samuel", $laravel_log_viewer->getFolderName()); } public function testSetFolderWithDefaultStoragePath() { $laravel_log_viewer = new LaravelLogViewer(); $laravel_log_viewer->setStoragePath(storage_path()); $laravel_log_viewer->setFolder('logs'); $this->assertEquals("logs", $laravel_log_viewer->getFolderName()); } public function testSetStoragePath() { $laravel_log_viewer = new LaravelLogViewer(); $laravel_log_viewer->setStoragePath(basename(__DIR__)); $this->assertEquals("tests", $laravel_log_viewer->getStoragePath()); } public function testPathToLogFile() { $laravel_log_viewer = new LaravelLogViewer(); $pathToLogFile = $laravel_log_viewer->pathToLogFile(storage_path(('logs/laravel.log'))); $this->assertEquals($pathToLogFile, storage_path('logs/laravel.log')); } public function testPathToLogFileWithArrayStoragePath() { $laravel_log_viewer = new LaravelLogViewer(); $laravel_log_viewer->setStoragePath([storage_path()]); $pathToLogFile = $laravel_log_viewer->pathToLogFile('laravel.log'); $this->assertEquals($pathToLogFile, 'laravel.log'); } public function testFailOnBadPathToLogFile() { $this->expectException(\Exception::class); $laravel_log_viewer = new LaravelLogViewer(); $laravel_log_viewer->setStoragePath(storage_path()); $laravel_log_viewer->setFolder('logs'); $laravel_log_viewer->pathToLogFile('newlogs/nolaravel.txt'); } public function testAll() { $laravel_log_viewer = new LaravelLogViewer(); $laravel_log_viewer->setStoragePath(__DIR__); $laravel_log_viewer->pathToLogFile(storage_path('logs/laravel.log')); $data = $laravel_log_viewer->all(); $this->assertEquals('local', $data[0]['context']); $this->assertEquals('error', $data[0]['level']); $this->assertEquals('danger', $data[0]['level_class']); $this->assertEquals('exclamation-triangle', $data[0]['level_img']); $this->assertEquals('2018-09-05 20:20:51', $data[0]['date']); } public function testAllWithEmptyFileName() { $laravel_log_viewer = new LaravelLogViewer(); $laravel_log_viewer->setStoragePath(__DIR__); $data = $laravel_log_viewer->all(); $this->assertEquals('local', $data[0]['context']); $this->assertEquals('error', $data[0]['level']); $this->assertEquals('danger', $data[0]['level_class']); $this->assertEquals('exclamation-triangle', $data[0]['level_img']); $this->assertEquals('2018-09-05 20:20:51', $data[0]['date']); } public function testFolderFiles() { $laravel_log_viewer = new LaravelLogViewer(); $laravel_log_viewer->setStoragePath(__DIR__); $data = $laravel_log_viewer->foldersAndFiles(); $this->assertIsArray($data); $this->assertIsArray($data); $this->assertNotEmpty($data); $this->assertStringContainsString('tests', $data[count(explode($data[0], '/')) - 1]); } public function testGetFolderFiles() { $laravel_log_viewer = new LaravelLogViewer(); $laravel_log_viewer->setStoragePath(__DIR__); $data = $laravel_log_viewer->getFolderFiles(); $this->assertIsArray($data); $this->assertNotEmpty($data, "Folder files is null"); } public function testGetFiles() { $laravel_log_viewer = new LaravelLogViewer(); $laravel_log_viewer->setStoragePath(storage_path()); $data = $laravel_log_viewer->getFiles(); $this->assertIsArray($data); $this->assertNotEmpty($data, "Folder files is null"); } public function testGetFolders() { $laravel_log_viewer = new LaravelLogViewer(); $laravel_log_viewer->setStoragePath(storage_path()); $data = $laravel_log_viewer->getFolders(); $this->assertIsArray($data); $this->assertNotEmpty($data, "files is null"); } public function testDirectoryStructure() { $log_viewer = new LaravelLogViewer(); ob_start(); $log_viewer->directoryTreeStructure(storage_path('logs'), $log_viewer->foldersAndFiles()); $data = ob_get_clean(); $this->assertIsString($data); $this->assertNotEmpty($data); } } ================================================ FILE: tests/laravel.log ================================================ [2018-09-05 20:20:51] local.ERROR: The "--versio" option does not exist. {"exception":"[object] (Symfony\\Component\\Console\\Exception\\RuntimeException(code: 0): The \"--versio\" option does not exist. at /x/y/z/vendor/symfony/console/Input/ArgvInput.php:217) [stacktrace] #0 /x/y/z/vendor/symfony/console/Input/ArgvInput.php(153): Symfony\\Component\\Console\\Input\\ArgvInput->addLongOption('versio', NULL) #1 /x/y/z/vendor/symfony/console/Input/ArgvInput.php(82): Symfony\\Component\\Console\\Input\\ArgvInput->parseLongOption('--versio') #2 /x/y/z/vendor/symfony/console/Input/Input.php(55): Symfony\\Component\\Console\\Input\\ArgvInput->parse() #3 /x/y/z/vendor/symfony/console/Command/Command.php(210): Symfony\\Component\\Console\\Input\\Input->bind(Object(Symfony\\Component\\Console\\Input\\InputDefinition)) #4 /x/y/z/vendor/symfony/console/Application.php(886): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput)) #5 /x/y/z/vendor/symfony/console/Application.php(262): Symfony\\Component\\Console\\Application->doRunCommand(Object(Symfony\\Component\\Console\\Command\\ListCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput)) #6 /x/y/z/vendor/symfony/console/Application.php(145): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput)) #7 /x/y/z/vendor/laravel/framework/src/Illuminate/Console/Application.php(89): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput)) #8 /x/y/z/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(122): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput)) #9 /x/y/z/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput)) #10 {main} "}