Skip to content

Commit

Permalink
Update LaravelLogViewer.php
Browse files Browse the repository at this point in the history
  • Loading branch information
rap2hpoutre committed Nov 24, 2014
1 parent c8517d9 commit 5898047
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@

class LaravelLogViewer
{

private static $file;

public static function setFile($file)
{
if (File::exists(storage_path() . '/logs/' . $file)) {
self::$file = storage_path() . '/logs/' . $file;
}
}

public static function all()
{
$log = array();
Expand All @@ -16,9 +26,14 @@ public static function all()

$pattern = '/\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\].*/';

$log_file = storage_path() . '/logs/laravel.log';
if (self::$file) {
$file = File::get(self::$file);
} else {
$log_file = self::getFiles();
$file = File::get($log_file[0]);
}


$file = File::get($log_file);

preg_match_all($pattern, $file, $headings);

Expand Down Expand Up @@ -65,7 +80,7 @@ public static function all()
'date' => $current[1],
'text' => $current[2],
'in_file' => isset($current[3]) ? $current[3] : null,
'stack' => $log_data[$i]
'stack' => $log_data[$i],
);
}
}
Expand All @@ -75,4 +90,16 @@ public static function all()
$log = array_reverse($log);
return $log;
}
}

public static function getFiles($basename = false)
{
$files = glob(storage_path() . '/logs/*');
$files = array_reverse($files);
if ($basename && is_array($files)) {
foreach ($files as $k => $file) {
$files[$k] = basename($file);
}
}
return $files;
}
}

0 comments on commit 5898047

Please sign in to comment.