Skip to content
This repository has been archived by the owner on Mar 21, 2018. It is now read-only.

Handle non-daily log files #81

Open
wants to merge 3 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
8 changes: 7 additions & 1 deletion src/Kmd/Logviewer/Logviewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ public function log()

$log_file = glob($this->path.'/log-'.$this->sapi.'*-'.$this->date.'.txt');

if (!empty($log_file)) {
// Looking for custom file, if daily $log_file not found
if (empty($log_file)) {
// $this->date contains custom file name
$log_file = array($this->path . '/' . $this->date);
}

if (!empty($log_file) && file_exists($log_file[0])) {
$this->empty = false;
$file = File::get($log_file[0]);

Expand Down
23 changes: 13 additions & 10 deletions src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

return array(

'base_url' => 'logviewer',
'filters' => array(
'global' => array(),
'view' => array(),
'delete' => array()
'base_url' => 'logviewer',
'filters' => array(
'global' => array(),
'view' => array(),
'delete' => array()
),
'log_dirs' => array('app' => storage_path().'/logs'),
'log_order' => 'asc', // Change to 'desc' for the latest entries first
'per_page' => 10,
'view' => 'logviewer::viewer',
'p_view' => 'pagination::slider'
'log_dirs' => array('app' => storage_path().'/logs'),
'log_order' => 'desc', // Change to 'desc' for the latest entries first
'per_page' => 10,
'view' => 'logviewer::viewer',
'p_view' => 'pagination::slider',

// Allow to use custom file list or custom file name filtering
'custom_files' => array(), // custom log files e.g. 'laravel.log'
'custom_glob_filter' => array(), // custom filter for glob e.g. '*.log'
);
27 changes: 26 additions & 1 deletion src/filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
if (!Lang::has('logviewer::logviewer.sapi')) {
App::setLocale('en');
}

$dirs = Config::get('logviewer::log_dirs');

// List daily files
foreach (Lang::get('logviewer::logviewer.sapi') as $sapi => $human) {
$logs[$sapi]['sapi'] = $human;
$dirs = Config::get('logviewer::log_dirs');

$files = array();

Expand All @@ -21,6 +24,28 @@
} else {
$files[$app] = array();
}

// List files from custom list
if (strpos(php_sapi_name(), $sapi) !== false) {
foreach (Config::get('logviewer::custom_files') as $f) {
if (file_exists($dir . '/' . $f) && !in_array(basename($f), $files[$app])) {
$files[$app][] = $f;
}
}

// List files from custom file filter
foreach (Config::get('logviewer::custom_glob_filter') as $filter) {
$custom_files = glob($dir . '/' . $filter, GLOB_BRACE);

if (is_array($custom_files)) {
foreach ($custom_files as $f) {
if (file_exists($f) && !in_array(basename($f), $files[$app])) {
$files[$app][] = basename($f);
}
}
}
}
}
}

$logs[$sapi]['logs'] = $files;
Expand Down