Skip to content

Commit 990fe6b

Browse files
cinorap2hpoutre
authored andcommitted
Regex update for Queue worker logs (#89)
* Update to make the regex to support a qeue log file. * Added docblock
1 parent 90ffe4a commit 990fe6b

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class LaravelLogViewer
2525
'critical' => 'danger',
2626
'alert' => 'danger',
2727
'emergency' => 'danger',
28+
'processed' => 'info',
2829
];
2930

3031
private static $levels_imgs = [
@@ -36,8 +37,26 @@ class LaravelLogViewer
3637
'critical' => 'warning',
3738
'alert' => 'warning',
3839
'emergency' => 'warning',
40+
'processed' => 'info'
3941
];
4042

43+
/**
44+
* Log levels that are used
45+
* @var array
46+
*/
47+
private static $log_levels = [
48+
'emergency',
49+
'alert',
50+
'critical',
51+
'error',
52+
'warning',
53+
'notice',
54+
'info',
55+
'debug',
56+
'processed'
57+
];
58+
59+
4160
const MAX_FILE_SIZE = 52428800; // Why? Uh... Sorry
4261

4362
/**
@@ -52,6 +71,11 @@ public static function setFile($file)
5271
}
5372
}
5473

74+
/**
75+
* @param $file
76+
* @return string
77+
* @throws \Exception
78+
*/
5579
public static function pathToLogFile($file)
5680
{
5781
$logsPath = storage_path('logs');
@@ -85,8 +109,6 @@ public static function all()
85109
{
86110
$log = array();
87111

88-
$log_levels = self::getLogLevels();
89-
90112
$pattern = '/\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\].*/';
91113

92114
if (!self::$file) {
@@ -113,18 +135,17 @@ public static function all()
113135

114136
foreach ($headings as $h) {
115137
for ($i=0, $j = count($h); $i < $j; $i++) {
116-
foreach ($log_levels as $level_key => $level_value) {
117-
if (strpos(strtolower($h[$i]), '.' . $level_value)) {
118-
119-
preg_match('/^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\].*?(\w+)\.' . $level_key . ': (.*?)( in .*?:[0-9]+)?$/', $h[$i], $current);
138+
foreach (self::$log_levels as $level) {
139+
if (strpos(strtolower($h[$i]), '.' . $level) || strpos(strtolower($h[$i]), $level . ':')) {
120140

141+
preg_match('/^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\](?:.*?(\w+)\.|.*?)' . $level . ': (.*?)( in .*?:[0-9]+)?$/i', $h[$i], $current);
121142
if (!isset($current[3])) continue;
122143

123144
$log[] = array(
124145
'context' => $current[2],
125-
'level' => $level_value,
126-
'level_class' => self::$levels_classes[$level_value],
127-
'level_img' => self::$levels_imgs[$level_value],
146+
'level' => $level,
147+
'level_class' => self::$levels_classes[$level],
148+
'level_img' => self::$levels_imgs[$level],
128149
'date' => $current[1],
129150
'text' => $current[3],
130151
'in_file' => isset($current[4]) ? $current[4] : null,
@@ -154,13 +175,4 @@ public static function getFiles($basename = false)
154175
}
155176
return array_values($files);
156177
}
157-
158-
/**
159-
* @return array
160-
*/
161-
private static function getLogLevels()
162-
{
163-
$class = new ReflectionClass(new LogLevel);
164-
return $class->getConstants();
165-
}
166178
}

0 commit comments

Comments
 (0)