2011-05-02 17:05:22 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorDaemonLogEventsView extends AphrontView {
|
|
|
|
|
|
|
|
private $events;
|
|
|
|
private $combinedLog;
|
|
|
|
|
|
|
|
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) {
|
|
|
|
throw new Exception("Call setUser() before rendering!");
|
|
|
|
}
|
|
|
|
|
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_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);
|
|
|
|
}
|
|
|
|
|
|
|
|
$more = null;
|
|
|
|
if ($more_chars) {
|
|
|
|
$more = number_format($more_chars);
|
|
|
|
$more = "\n<... {$more} more characters ...>";
|
|
|
|
} else if ($more_lines) {
|
|
|
|
$more = number_format($more_lines);
|
|
|
|
$more = "\n<... {$more} more lines ...>";
|
|
|
|
}
|
|
|
|
|
2011-05-02 17:05:22 -07:00
|
|
|
$row = array(
|
|
|
|
phutil_escape_html($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),
|
2011-07-03 09:47:31 -07:00
|
|
|
str_replace("\n", '<br />', phutil_escape_html($message.$more)),
|
2011-05-02 17:05:22 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
if ($this->combinedLog) {
|
|
|
|
array_unshift(
|
|
|
|
$row,
|
|
|
|
phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '/daemon/log/'.$event->getLogID().'/',
|
|
|
|
),
|
|
|
|
phutil_escape_html('Daemon '.$event->getLogID())));
|
|
|
|
}
|
|
|
|
|
|
|
|
$rows[] = $row;
|
|
|
|
}
|
|
|
|
|
|
|
|
$classes = array(
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
'right',
|
|
|
|
'wide wrap',
|
|
|
|
);
|
|
|
|
|
|
|
|
$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();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|