2011-05-02 17:05:22 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorDaemonLogEventsView extends AphrontView {
|
|
|
|
|
|
|
|
private $events;
|
|
|
|
private $combinedLog;
|
2013-07-23 12:30:58 -07:00
|
|
|
private $showFullMessage;
|
|
|
|
|
|
|
|
|
|
|
|
public function setShowFullMessage($show_full_message) {
|
|
|
|
$this->showFullMessage = $show_full_message;
|
|
|
|
return $this;
|
|
|
|
}
|
2011-05-02 17:05:22 -07:00
|
|
|
|
|
|
|
public function setEvents(array $events) {
|
2012-04-03 12:10:45 -07:00
|
|
|
assert_instances_of($events, 'PhabricatorDaemonLogEvent');
|
2011-05-02 17:05:22 -07:00
|
|
|
$this->events = $events;
|
2012-04-02 18:35:09 -07:00
|
|
|
return $this;
|
2011-05-02 17:05:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setCombinedLog($is_combined) {
|
|
|
|
$this->combinedLog = $is_combined;
|
2012-04-02 18:35:09 -07:00
|
|
|
return $this;
|
2011-05-02 17:05:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function render() {
|
|
|
|
$rows = array();
|
|
|
|
|
Use phabricator_ time functions in more places
Summary:
Replace some more date() calls with locale-aware calls.
Also, at least on my system, the DateTimeZone / DateTime stuff didn't actually
work and always rendered in UTC. Fixed that.
Test Plan:
Viewed daemon console, differential revisions, files, and maniphest timestamps
in multiple timezones.
Reviewed By: toulouse
Reviewers: toulouse, fratrik, jungejason, aran, tuomaspelkonen
CC: aran, toulouse
Differential Revision: 530
2011-06-26 09:22:52 -07:00
|
|
|
if (!$this->user) {
|
2015-05-14 07:53:52 +10:00
|
|
|
throw new PhutilInvalidStateException('setUser');
|
Use phabricator_ time functions in more places
Summary:
Replace some more date() calls with locale-aware calls.
Also, at least on my system, the DateTimeZone / DateTime stuff didn't actually
work and always rendered in UTC. Fixed that.
Test Plan:
Viewed daemon console, differential revisions, files, and maniphest timestamps
in multiple timezones.
Reviewed By: toulouse
Reviewers: toulouse, fratrik, jungejason, aran, tuomaspelkonen
CC: aran, toulouse
Differential Revision: 530
2011-06-26 09:22:52 -07:00
|
|
|
}
|
|
|
|
|
2011-05-02 17:05:22 -07:00
|
|
|
foreach ($this->events as $event) {
|
2011-07-03 09:47:31 -07:00
|
|
|
|
|
|
|
// Limit display log size. If a daemon gets stuck in an output loop this
|
|
|
|
// page can be like >100MB if we don't truncate stuff. Try to do cheap
|
|
|
|
// line-based truncation first, and fall back to expensive UTF-8 character
|
|
|
|
// truncation if that doesn't get things short enough.
|
|
|
|
|
|
|
|
$message = $event->getMessage();
|
|
|
|
$more = null;
|
2013-07-23 12:30:58 -07:00
|
|
|
|
|
|
|
if (!$this->showFullMessage) {
|
|
|
|
$more_lines = null;
|
|
|
|
$more_chars = null;
|
|
|
|
$line_limit = 12;
|
|
|
|
if (substr_count($message, "\n") > $line_limit) {
|
|
|
|
$message = explode("\n", $message);
|
|
|
|
$more_lines = count($message) - $line_limit;
|
|
|
|
$message = array_slice($message, 0, $line_limit);
|
|
|
|
$message = implode("\n", $message);
|
|
|
|
}
|
|
|
|
|
|
|
|
$char_limit = 8192;
|
|
|
|
if (strlen($message) > $char_limit) {
|
|
|
|
$message = phutil_utf8v($message);
|
|
|
|
$more_chars = count($message) - $char_limit;
|
|
|
|
$message = array_slice($message, 0, $char_limit);
|
|
|
|
$message = implode('', $message);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($more_chars) {
|
|
|
|
$more = new PhutilNumber($more_chars);
|
2014-06-09 11:36:49 -07:00
|
|
|
$more = pht('Show %d more character(s)...', $more);
|
2013-07-23 12:30:58 -07:00
|
|
|
} else if ($more_lines) {
|
|
|
|
$more = new PhutilNumber($more_lines);
|
2014-06-09 11:36:49 -07:00
|
|
|
$more = pht('Show %d more line(s)...', $more);
|
2013-07-23 12:30:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($more) {
|
|
|
|
$id = $event->getID();
|
|
|
|
$more = array(
|
|
|
|
"\n...\n",
|
|
|
|
phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => "/daemon/event/{$id}/",
|
|
|
|
),
|
|
|
|
$more),
|
|
|
|
);
|
|
|
|
}
|
2011-07-03 09:47:31 -07:00
|
|
|
}
|
|
|
|
|
2011-05-02 17:05:22 -07:00
|
|
|
$row = array(
|
2013-02-13 14:50:15 -08:00
|
|
|
$event->getLogType(),
|
Use phabricator_ time functions in more places
Summary:
Replace some more date() calls with locale-aware calls.
Also, at least on my system, the DateTimeZone / DateTime stuff didn't actually
work and always rendered in UTC. Fixed that.
Test Plan:
Viewed daemon console, differential revisions, files, and maniphest timestamps
in multiple timezones.
Reviewed By: toulouse
Reviewers: toulouse, fratrik, jungejason, aran, tuomaspelkonen
CC: aran, toulouse
Differential Revision: 530
2011-06-26 09:22:52 -07:00
|
|
|
phabricator_date($event->getEpoch(), $this->user),
|
|
|
|
phabricator_time($event->getEpoch(), $this->user),
|
2013-07-23 12:30:58 -07:00
|
|
|
array(
|
|
|
|
$message,
|
|
|
|
$more,
|
|
|
|
),
|
2011-05-02 17:05:22 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
if ($this->combinedLog) {
|
|
|
|
array_unshift(
|
|
|
|
$row,
|
2013-01-17 18:43:35 -08:00
|
|
|
phutil_tag(
|
2011-05-02 17:05:22 -07:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '/daemon/log/'.$event->getLogID().'/',
|
|
|
|
),
|
2015-05-22 17:27:56 +10:00
|
|
|
pht('Daemon %s', $event->getLogID())));
|
2011-05-02 17:05:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
$rows[] = $row;
|
|
|
|
}
|
|
|
|
|
|
|
|
$classes = array(
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
'right',
|
2013-07-23 12:30:58 -07:00
|
|
|
'wide prewrap',
|
2011-05-02 17:05:22 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
$headers = array(
|
|
|
|
'Type',
|
|
|
|
'Date',
|
|
|
|
'Time',
|
|
|
|
'Message',
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($this->combinedLog) {
|
|
|
|
array_unshift($classes, 'pri');
|
|
|
|
array_unshift($headers, 'Daemon');
|
|
|
|
}
|
|
|
|
|
|
|
|
$log_table = new AphrontTableView($rows);
|
|
|
|
$log_table->setHeaders($headers);
|
|
|
|
$log_table->setColumnClasses($classes);
|
|
|
|
|
|
|
|
return $log_table->render();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|