示例#1
0
 public function transform(array $data)
 {
     $logs = new LogCollection();
     foreach ($data as $line) {
         $log = json_decode($line, true);
         if ($log) {
             $logObj = new Log(isset($log['message']) ? $log['message'] : null, isset($log['context']) ? $log['context'] : null, isset($log['level_name']) ? $log['level_name'] : null, isset($log['channel']) ? $log['channel'] : null, isset($log['datetime']['date']) ? new \DateTime($log['datetime']['date']) : null);
             $logs->addLog($logObj);
         }
     }
     return $logs;
 }
示例#2
0
 public function transform(array $data)
 {
     $logs = new LogCollection();
     foreach ($data as $line) {
         preg_match("/\\[(?P<timestamp>.*)\\] (?P<logger>\\w+).(?P<level>\\w+): (?P<message>[^\\[\\{]+) (?P<context>[\\[\\{].*[\\]\\}]) (?P<extra>[\\[\\{].*[\\]\\}])/", $line, $log);
         if ($log) {
             $logObj = new Log(isset($log['message']) ? $log['message'] : null, isset($log['context']) ? $log['context'] : null, isset($log['level']) ? $log['level'] : null, isset($log['logger']) ? $log['logger'] : null, isset($log['timestamp']) ? new \DateTime($log['timestamp']) : null);
             $logs->addLog($logObj);
         }
     }
     return $logs;
 }