Skip to content

Commit 5d17466

Browse files
committed
Update LaravelLogViewer.php
1 parent e6a3f0b commit 5d17466

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,20 @@ public static function all()
4242
{
4343
$log = array();
4444

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

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

5049
$file = self::getCurrentFile();
5150

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

53+
if (!is_array($headings)) return $log;
54+
5455
$log_data = preg_split($pattern, $file);
5556

5657
if ($log_data[0] < 1) {
57-
$trash = array_shift($log_data);
58-
unset($trash);
58+
array_shift($log_data);
5959
}
6060

6161
$levels_classes = [
@@ -76,28 +76,23 @@ public static function all()
7676
'critical' => 'warning',
7777
'alert' => 'warning',
7878
];
79-
80-
81-
if (is_array($headings)) {
82-
foreach ($headings as $h) {
83-
for ($i=0, $j = count($h); $i < $j; $i++) {
84-
foreach ($log_levels as $ll) {
85-
if (strpos(strtolower($h[$i]), strtolower('.'.$ll))) {
86-
87-
$level = strtoupper($ll);
88-
89-
preg_match('/^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\].*?\.' . $level . ': (.*?)( in .*?:[0-9]+)?$/', $h[$i], $current);
90-
91-
$log[] = array(
92-
'level' => $ll,
93-
'level_class' => $levels_classes[$ll],
94-
'level_img' => $levels_imgs[$ll],
95-
'date' => isset($current[1]) ? $current[1] : null,
96-
'text' => isset($current[2]) ? $current[2] : null,
97-
'in_file' => isset($current[3]) ? $current[3] : null,
98-
'stack' => preg_replace("/^\n*/", '', $log_data[$i])
99-
);
100-
}
79+
80+
foreach ($headings as $h) {
81+
for ($i=0, $j = count($h); $i < $j; $i++) {
82+
foreach ($log_levels as $level_key => $level_value) {
83+
if (strpos(strtolower($h[$i]), '.' . $level_value)) {
84+
85+
preg_match('/^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\].*?\.' . $level_key . ': (.*?)( in .*?:[0-9]+)?$/', $h[$i], $current);
86+
87+
$log[] = array(
88+
'level' => $level_value,
89+
'level_class' => $levels_classes[$level_value],
90+
'level_img' => $levels_imgs[$level_value],
91+
'date' => isset($current[1]) ? $current[1] : null,
92+
'text' => isset($current[2]) ? $current[2] : null,
93+
'in_file' => isset($current[3]) ? $current[3] : null,
94+
'stack' => preg_replace("/^\n*/", '', $log_data[$i])
95+
);
10196
}
10297
}
10398
}
@@ -137,4 +132,13 @@ private static function getCurrentFile()
137132

138133
return File::get(self::$file);
139134
}
135+
136+
/**
137+
* @return array
138+
*/
139+
private static function getLogLevels()
140+
{
141+
$class = new ReflectionClass(new LogLevel);
142+
return $class->getConstants();
143+
}
140144
}

0 commit comments

Comments
 (0)