Example #1
0
 public function getLineCollection()
 {
     $maxCollectionSize = max(1, $this->mHelper('config')->getLogViewerMaxCollectionSize());
     $regExp = '/(\\d+-\\d+-\\d+T\\d+[0-9\\-+T:]+?)\\s+?([A-Z]+?)\\s+?\\((\\d+)\\)\\:\\s+?(.+?)(?:(?=(?:\\d+-\\d+-\\d+T\\d+[0-9\\-+T:]+?))|$)/si';
     $contents = file_get_contents($this->getPath());
     $lines = array();
     if (preg_match_all($regExp, $contents, $matches, PREG_SET_ORDER)) {
         foreach ($matches as $match) {
             $lines[] = $match[0];
         }
     }
     $lines = array_reverse($lines);
     $collection = Mage::getModel('ewcore/system_log_file_line_collection');
     foreach ($lines as $line) {
         if ($collection->count() >= $maxCollectionSize) {
             break;
         }
         $line = trim($line);
         if (preg_match($regExp, $line, $match)) {
             list($date, $priorityName, $priority, $message) = array_slice($match, 1);
             $message = trim($message);
             if ($date and $priorityName and $priority and $message) {
                 $item = new Varien_Object();
                 $item->setDate($date);
                 $item->setPriorityName($priorityName);
                 $item->setPriority($priority);
                 $item->setMessage($message);
                 $collection->addItem($item);
             }
         }
     }
     return $collection;
 }