public function get(LogFile $logFile)
 {
     $args = self::getFilesystem($logFile->getArgs());
     $file = $args['filesystem']->read($args['path']);
     if (pathinfo($args['path'])['extension'] === 'gz') {
         $file = gzdecode($file);
     }
     $lines = explode("\n", $file);
     $parser = new LineLogParser();
     if (isset($args['pattern'])) {
         $hasCustomPattern = true;
         $parser->registerPattern('custom', $args['pattern']);
     } else {
         $hasCustomPattern = false;
     }
     foreach ($lines as $line) {
         $entry = $hasCustomPattern ? $parser->parse($line, 0, 'custom') : $parser->parse($line, 0);
         if (count($entry) > 0) {
             if (!$logFile->hasLogger($entry['logger'])) {
                 $logFile->addLogger($entry['logger']);
             }
             $logFile->addLine($entry);
         }
     }
     if ($this->reverse) {
         $logFile->reverseLines();
     }
     return $logFile;
 }
Example #2
0
 private function loadSource(LogFile $logFile)
 {
     $args = $logFile->getArgs();
     switch ($args['type']) {
         case 'ftp':
             $filesystem = new Filesystem(new Ftp(array('host' => $args['host'], 'username' => $args['username'], 'password' => $args['password'], 'passive' => true, 'ssl' => false)));
             break;
         case 'local':
             $filesystem = new Filesystem(new Local(dirname($args['path'])));
             $args['path'] = basename($args['path']);
             break;
         default:
             throw new \InvalidArgumentException("Invalid log file type: \"" . $args['type'] . "\"");
     }
     $file = $filesystem->read($args['path']);
     $lines = explode("\n", $file);
     $parser = new LineLogParser();
     if (isset($args['pattern'])) {
         $hasCustomPattern = true;
         $parser->registerPattern('custom', $args['pattern']);
     } else {
         $hasCustomPattern = false;
     }
     foreach ($lines as $line) {
         $entry = $hasCustomPattern ? $parser->parse($line, 0, 'custom') : $parser->parse($line, 0);
         if (count($entry) > 0) {
             if (!$logFile->hasLogger($entry['logger'])) {
                 $logFile->addLogger($entry['logger']);
             }
             $logFile->addLine($entry);
         }
     }
     if ($this->reverse) {
         $logFile->reverseLines();
     }
     $this->writeCache($logFile);
     return $logFile;
 }