diff --git a/.gitignore b/.gitignore index 8c551bf..bc0db67 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /vendor composer.lock /.idea -/build \ No newline at end of file +/build +.gitconfig \ No newline at end of file diff --git a/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php b/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php index b224eda..998bd7e 100644 --- a/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php +++ b/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php @@ -170,7 +170,16 @@ public function all() 'stack' => '', ]]; } - + if (is_dir($this->file)) + { + return [[ + 'context' => '', + 'level' => '', + 'date' => null, + 'text' => 'Log file "' . $this->file . '" is DIR', + 'stack' => '', + ]]; + } $file = app('files')->get($this->file); preg_match_all($this->pattern->getPattern('logs'), $file, $headings); @@ -245,13 +254,18 @@ public function foldersAndFiles($path = null) { $contents = array(); $dir = $path ? $path : $this->storage_path; + $ignoreFiles = function_exists('config') ? config('logviewer.ignore_files', []) : []; + foreach (scandir($dir) as $node) { if ($node == '.' || $node == '..') continue; $path = $dir . '\\' . $node; + $fpath = $dir . '/' . $node; if (is_dir($path)) { $contents[$path] = $this->foldersAndFiles($path); } else { - $contents[] = $path; + if (!empty($ignoreFiles) && in_array($node, $ignoreFiles)) continue; + + $contents[] = $fpath; } } @@ -283,9 +297,11 @@ public function getFolders($folder = '') * @param bool $basename * @return array */ - public function getFolderFiles($basename = false) + public function getFolderFiles($basename = false, $fullPath = false) { - return $this->getFiles($basename, $this->folder); + $folder = $fullPath ? $this->folder : str_replace($this->storage_path, '', $this->folder); + + return $this->getFiles($basename, $folder); } /** @@ -335,15 +351,15 @@ public function setStoragePath($path) public static function directoryTreeStructure($storage_path, array $array) { foreach ($array as $k => $v) { - if (is_dir($k)) { + if (is_dir($v)) { $exploded = explode("\\", $k); $show = last($exploded); echo '
'; diff --git a/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewerServiceProvider.php b/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewerServiceProvider.php index 18114b3..27f156b 100644 --- a/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewerServiceProvider.php +++ b/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewerServiceProvider.php @@ -44,7 +44,7 @@ public function boot() */ public function register() { - // + $this->mergeConfigFrom(realpath(__DIR__ . '/../../config/logviewer.php'), 'logviewer'); } /** diff --git a/src/config/logviewer.php b/src/config/logviewer.php index 90c2a6f..0338a4e 100644 --- a/src/config/logviewer.php +++ b/src/config/logviewer.php @@ -12,4 +12,8 @@ 'max_file_size' => 52428800, // size in Byte 'pattern' => env('LOGVIEWER_PATTERN', '*.log'), 'storage_path' => env('LOGVIEWER_STORAGE_PATH', storage_path('logs')), + 'ignore_files' => [ + '.DS_Store', + '.gitignore' + ] ]; diff --git a/src/controllers/LogViewerController.php b/src/controllers/LogViewerController.php index f8cf62a..8411642 100644 --- a/src/controllers/LogViewerController.php +++ b/src/controllers/LogViewerController.php @@ -49,7 +49,7 @@ 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); + $folderFiles = $this->log_viewer->getFolderFiles(false); } if ($this->request->input('l')) { $this->log_viewer->setFile(Crypt::decrypt($this->request->input('l'))); @@ -62,9 +62,9 @@ public function index() $data = [ 'logs' => $this->log_viewer->all(), 'folders' => $this->log_viewer->getFolders(), - 'current_folder' => $this->log_viewer->getFolderName(), + 'current_folder' => $this->log_viewer->getFolderName() ?? $this->log_viewer->getStoragePath(), 'folder_files' => $folderFiles, - 'files' => $this->log_viewer->getFiles(true), + 'files' => $this->log_viewer->getFiles(false), 'current_file' => $this->log_viewer->getFileName(), 'standardFormat' => true, 'structure' => $this->log_viewer->foldersAndFiles(), @@ -85,6 +85,8 @@ public function index() } } + $data['show_files'] = (!empty($data['folder_files']) ? $data['folder_files'] : $data['files']); + return app('view')->make($this->view_log, $data); }