Skip to content

Commit

Permalink
Regex update for Queue worker logs (#89)
Browse files Browse the repository at this point in the history
* Update to make the regex to support a qeue log file.

* Added docblock
  • Loading branch information
cino authored and rap2hpoutre committed Apr 23, 2017
1 parent 90ffe4a commit 990fe6b
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class LaravelLogViewer
'critical' => 'danger',
'alert' => 'danger',
'emergency' => 'danger',
'processed' => 'info',
];

private static $levels_imgs = [
Expand All @@ -36,8 +37,26 @@ class LaravelLogViewer
'critical' => 'warning',
'alert' => 'warning',
'emergency' => 'warning',
'processed' => 'info'
];

/**
* Log levels that are used
* @var array
*/
private static $log_levels = [
'emergency',
'alert',
'critical',
'error',
'warning',
'notice',
'info',
'debug',
'processed'
];


const MAX_FILE_SIZE = 52428800; // Why? Uh... Sorry

/**
Expand All @@ -52,6 +71,11 @@ public static function setFile($file)
}
}

/**
* @param $file
* @return string
* @throws \Exception
*/
public static function pathToLogFile($file)
{
$logsPath = storage_path('logs');
Expand Down Expand Up @@ -85,8 +109,6 @@ public static function all()
{
$log = array();

$log_levels = self::getLogLevels();

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

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

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})\].*?(\w+)\.' . $level_key . ': (.*?)( in .*?:[0-9]+)?$/', $h[$i], $current);
foreach (self::$log_levels as $level) {
if (strpos(strtolower($h[$i]), '.' . $level) || strpos(strtolower($h[$i]), $level . ':')) {

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

$log[] = array(
'context' => $current[2],
'level' => $level_value,
'level_class' => self::$levels_classes[$level_value],
'level_img' => self::$levels_imgs[$level_value],
'level' => $level,
'level_class' => self::$levels_classes[$level],
'level_img' => self::$levels_imgs[$level],
'date' => $current[1],
'text' => $current[3],
'in_file' => isset($current[4]) ? $current[4] : null,
Expand Down Expand Up @@ -154,13 +175,4 @@ public static function getFiles($basename = false)
}
return array_values($files);
}

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

0 comments on commit 990fe6b

Please sign in to comment.