Skip to content

Commit

Permalink
Fix Wrong log path issue
Browse files Browse the repository at this point in the history
  • Loading branch information
anitamourya4it committed Aug 2, 2022
1 parent 1dfd871 commit f395db3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/vendor
composer.lock
/.idea
/build
/build
.gitconfig
30 changes: 23 additions & 7 deletions src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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 '<div class="list-group folder">
<a href="?f=' . \Illuminate\Support\Facades\Crypt::encrypt($k) . '">
<a href="?f=' . \Illuminate\Support\Facades\Crypt::encrypt($v) . '">
<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span
class="fa fa-folder"></span> ' . $show . '
class="fa fa-folder"></span> ' . basename($v) . '
</a>
</div>';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function boot()
*/
public function register()
{
//
$this->mergeConfigFrom(realpath(__DIR__ . '/../../config/logviewer.php'), 'logviewer');
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/config/logviewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
];
8 changes: 5 additions & 3 deletions src/controllers/LogViewerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
Expand All @@ -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(),
Expand All @@ -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);
}

Expand Down

0 comments on commit f395db3

Please sign in to comment.