示例#1
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;
 }
示例#2
0
 protected static function lintCheckFileAccessible(LogFile $logFile)
 {
     $return = ['message' => 'Checking if "' . $logFile->getName() . '" is accessible'];
     try {
         if (!LogFileCache::isSourceFileAccessible($logFile)) {
             throw new \Exception('File does not exist on target file system.');
         }
         $return['status'] = 'ok';
     } catch (\Exception $e) {
         $return['status'] = 'fail';
         $return['error'] = $e->getMessage();
     }
     return $return;
 }
示例#3
0
 public static function isAccessible(LogFile $logFile)
 {
     $args = self::getFilesystem($logFile->getArgs());
     return $args['filesystem']->has($args['path']);
 }
示例#4
0
 private function getFilename(LogFile $logFile)
 {
     return base64_encode($logFile->getIdentifier());
 }