public function load()
 {
     switch ($this->args['type']) {
         case 'ftp':
             $this->filesystem = new Filesystem(new Ftp(array('host' => $this->args['host'], 'username' => $this->args['username'], 'password' => $this->args['password'], 'passive' => true, 'ssl' => false)));
             break;
         case 'local':
             $this->filesystem = new Filesystem(new Local(dirname($this->args['path'])));
             $this->args['path'] = basename($this->args['path']);
             break;
         default:
             throw new \InvalidArgumentException("Invalid log file type: \"" . $this->args['type'] . "\"");
     }
     $file = $this->filesystem->read($this->args['path']);
     $lines = explode("\n", $file);
     $parser = new LineLogParser();
     if (isset($this->args['pattern'])) {
         $hasCustomPattern = true;
         $parser->registerPattern('custom', $this->args['pattern']);
     } else {
         $hasCustomPattern = false;
     }
     $this->loggers = new ArrayCollection();
     foreach ($lines as $line) {
         $entry = $hasCustomPattern ? $parser->parse($line, 0, 'custom') : $parser->parse($line, 0);
         if (count($entry) > 0) {
             if (!$this->loggers->contains($entry['logger'])) {
                 $this->loggers->add($entry['logger']);
             }
             $this->lines[] = $entry;
         }
     }
     return $this;
 }
Esempio n. 2
0
 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;
 }
Esempio n. 3
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;
 }