[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/daemon/view/ -> PhabricatorDaemonLogEventsView.php (source)

   1  <?php
   2  
   3  final class PhabricatorDaemonLogEventsView extends AphrontView {
   4  
   5    private $events;
   6    private $combinedLog;
   7    private $showFullMessage;
   8  
   9  
  10    public function setShowFullMessage($show_full_message) {
  11      $this->showFullMessage = $show_full_message;
  12      return $this;
  13    }
  14  
  15    public function setEvents(array $events) {
  16      assert_instances_of($events, 'PhabricatorDaemonLogEvent');
  17      $this->events = $events;
  18      return $this;
  19    }
  20  
  21    public function setCombinedLog($is_combined) {
  22      $this->combinedLog = $is_combined;
  23      return $this;
  24    }
  25  
  26    public function render() {
  27      $rows = array();
  28  
  29      if (!$this->user) {
  30        throw new Exception('Call setUser() before rendering!');
  31      }
  32  
  33      foreach ($this->events as $event) {
  34  
  35        // Limit display log size. If a daemon gets stuck in an output loop this
  36        // page can be like >100MB if we don't truncate stuff. Try to do cheap
  37        // line-based truncation first, and fall back to expensive UTF-8 character
  38        // truncation if that doesn't get things short enough.
  39  
  40        $message = $event->getMessage();
  41        $more = null;
  42  
  43        if (!$this->showFullMessage) {
  44          $more_lines = null;
  45          $more_chars = null;
  46          $line_limit = 12;
  47          if (substr_count($message, "\n") > $line_limit) {
  48            $message = explode("\n", $message);
  49            $more_lines = count($message) - $line_limit;
  50            $message = array_slice($message, 0, $line_limit);
  51            $message = implode("\n", $message);
  52          }
  53  
  54          $char_limit = 8192;
  55          if (strlen($message) > $char_limit) {
  56            $message = phutil_utf8v($message);
  57            $more_chars = count($message) - $char_limit;
  58            $message = array_slice($message, 0, $char_limit);
  59            $message = implode('', $message);
  60          }
  61  
  62          if ($more_chars) {
  63            $more = new PhutilNumber($more_chars);
  64            $more = pht('Show %d more character(s)...', $more);
  65          } else if ($more_lines) {
  66            $more = new PhutilNumber($more_lines);
  67            $more = pht('Show %d more line(s)...', $more);
  68          }
  69  
  70          if ($more) {
  71            $id = $event->getID();
  72            $more = array(
  73              "\n...\n",
  74              phutil_tag(
  75                'a',
  76                array(
  77                  'href' => "/daemon/event/{$id}/",
  78                ),
  79                $more),
  80            );
  81          }
  82        }
  83  
  84        $row = array(
  85          $event->getLogType(),
  86          phabricator_date($event->getEpoch(), $this->user),
  87          phabricator_time($event->getEpoch(), $this->user),
  88          array(
  89            $message,
  90            $more,
  91          ),
  92        );
  93  
  94        if ($this->combinedLog) {
  95          array_unshift(
  96            $row,
  97            phutil_tag(
  98              'a',
  99              array(
 100                'href' => '/daemon/log/'.$event->getLogID().'/',
 101              ),
 102              'Daemon '.$event->getLogID()));
 103        }
 104  
 105        $rows[] = $row;
 106      }
 107  
 108      $classes = array(
 109        '',
 110        '',
 111        'right',
 112        'wide prewrap',
 113      );
 114  
 115      $headers = array(
 116        'Type',
 117        'Date',
 118        'Time',
 119        'Message',
 120      );
 121  
 122      if ($this->combinedLog) {
 123        array_unshift($classes, 'pri');
 124        array_unshift($headers, 'Daemon');
 125      }
 126  
 127      $log_table = new AphrontTableView($rows);
 128      $log_table->setHeaders($headers);
 129      $log_table->setColumnClasses($classes);
 130  
 131      return $log_table->render();
 132    }
 133  
 134  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1