Barryvdh\Debugbar\DataCollector\LogsCollector::getLogs PHP Method

getLogs() public method

Search a string for log entries Based on https://github.com/mikemand/logviewer/blob/master/src/Kmd/Logviewer/Logviewer.php by mikemand
public getLogs ( $file ) : array
$file
return array
    public function getLogs($file)
    {
        $pattern = "/\\[\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\].*/";
        $log_levels = $this->getLevels();
        // There has GOT to be a better way of doing this...
        preg_match_all($pattern, $file, $headings);
        $log_data = preg_split($pattern, $file);
        $log = [];
        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))) {
                        $log[] = ['level' => $ll, 'header' => $h[$i], 'stack' => $log_data[$i]];
                    }
                }
            }
        }
        $log = array_reverse($log);
        return $log;
    }