Skip to content

Commit

Permalink
Update LaravelLogViewer.php
Browse files Browse the repository at this point in the history
  • Loading branch information
rap2hpoutre committed Apr 7, 2015
1 parent e6a3f0b commit 5d17466
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ public static function all()
{
$log = array();

$class = new ReflectionClass(new LogLevel);
$log_levels = $class->getConstants();
$log_levels = self::getLogLevels();

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

$file = self::getCurrentFile();

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

if (!is_array($headings)) return $log;

$log_data = preg_split($pattern, $file);

if ($log_data[0] < 1) {
$trash = array_shift($log_data);
unset($trash);
array_shift($log_data);
}

$levels_classes = [
Expand All @@ -76,28 +76,23 @@ public static function all()
'critical' => 'warning',
'alert' => 'warning',
];


if (is_array($headings)) {
foreach ($headings as $h) {
for ($i=0, $j = count($h); $i < $j; $i++) {
foreach ($log_levels as $ll) {
if (strpos(strtolower($h[$i]), strtolower('.'.$ll))) {

$level = strtoupper($ll);

preg_match('/^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\].*?\.' . $level . ': (.*?)( in .*?:[0-9]+)?$/', $h[$i], $current);

$log[] = array(
'level' => $ll,
'level_class' => $levels_classes[$ll],
'level_img' => $levels_imgs[$ll],
'date' => isset($current[1]) ? $current[1] : null,
'text' => isset($current[2]) ? $current[2] : null,
'in_file' => isset($current[3]) ? $current[3] : null,
'stack' => preg_replace("/^\n*/", '', $log_data[$i])
);
}

foreach ($headings as $h) {
for ($i=0, $j = count($h); $i < $j; $i++) {
foreach ($log_levels as $level_key => $level_value) {
if (strpos(strtolower($h[$i]), '.' . $level_value)) {

preg_match('/^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\].*?\.' . $level_key . ': (.*?)( in .*?:[0-9]+)?$/', $h[$i], $current);

$log[] = array(
'level' => $level_value,
'level_class' => $levels_classes[$level_value],
'level_img' => $levels_imgs[$level_value],
'date' => isset($current[1]) ? $current[1] : null,
'text' => isset($current[2]) ? $current[2] : null,
'in_file' => isset($current[3]) ? $current[3] : null,
'stack' => preg_replace("/^\n*/", '', $log_data[$i])
);
}
}
}
Expand Down Expand Up @@ -137,4 +132,13 @@ private static function getCurrentFile()

return File::get(self::$file);
}

/**
* @return array
*/
private static function getLogLevels()
{
$class = new ReflectionClass(new LogLevel);
return $class->getConstants();
}
}

0 comments on commit 5d17466

Please sign in to comment.