Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Wrong log path issue#272 #275

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
47 changes: 34 additions & 13 deletions src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ public function getFolderName()
return $this->folder;
}

public function getCurrentFolder()
{
return str_replace($this->storage_path, '', $this->folder);
}

/**
* @return string
*/
Expand Down Expand Up @@ -170,7 +175,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 +259,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 +302,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 : $this->getCurrentFolder();

return $this->getFiles($basename, $folder);
}

/**
Expand Down Expand Up @@ -335,15 +356,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 All @@ -359,12 +380,12 @@ class="fa fa-folder"></span> ' . $show . '
$file = $v;


echo '<div class="list-group">
<a href="?l=' . \Illuminate\Support\Facades\Crypt::encrypt($file) . '&f=' . \Illuminate\Support\Facades\Crypt::encrypt($folder) . '">
<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span
class="fa fa-file"></span> ' . $show2 . '
</a>
</div>';
// echo '<div class="list-group">
// <a href="?l=' . \Illuminate\Support\Facades\Crypt::encrypt($file) . '&f=' . \Illuminate\Support\Facades\Crypt::encrypt($folder) . '">
// <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <span
// class="fa fa-file"></span> ' . basename($show2) . '
// </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, $this->log_viewer->getCurrentFolder()),
'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
16 changes: 13 additions & 3 deletions src/views/log.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,22 @@ function resetTheme() {
@foreach($folders as $folder)
<div class="list-group-item">
<?php
echo '<div class="list-group folder">
<a href="?f=' . \Illuminate\Support\Facades\Crypt::encrypt($storage_path) . '">
<span></span><span
class="fa fa-folder"></span> ' . basename($storage_path) . '
</a>
</div>';

\Rap2hpoutre\LaravelLogViewer\LaravelLogViewer::DirectoryTreeStructure( $storage_path, $structure );
?>

</div>
@endforeach
@foreach($files as $file)
<a href="?l={{ \Illuminate\Support\Facades\Crypt::encrypt($file) }}"
@foreach($show_files as $file)
<a href="?l={{ \Illuminate\Support\Facades\Crypt::encrypt($file) }}&f={{ \Illuminate\Support\Facades\Crypt::encrypt($current_folder) }}"
class="list-group-item @if ($current_file == $file) llv-active @endif">
{{$file}}
{{basename($file)}}
</a>
@endforeach
</div>
Expand All @@ -204,6 +211,9 @@ class="list-group-item @if ($current_file == $file) llv-active @endif">
Log file >50M, please download it.
</div>
@else

<h1> {{ str_replace($storage_path, '', $current_folder)}}</h1>
<br/>
<table id="table-log" class="table table-striped" data-ordering-index="{{ $standardFormat ? 2 : 0 }}">
<thead>
<tr>
Expand Down