mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-11 23:31:03 +01:00
Daemons - move combined log to console
Summary: Fixes T5405. Test Plan: ran a few commands (log, log --id X --id Y, log --id BADX, log --id BADX --id BADY) and verified good output Reviewers: epriestley Reviewed By: epriestley Subscribers: epriestley, Korvin Maniphest Tasks: T5405 Differential Revision: https://secure.phabricator.com/D10371
This commit is contained in:
parent
2fdd7f0f3d
commit
06882a99cf
6 changed files with 41 additions and 74 deletions
|
@ -1375,7 +1375,6 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorCustomFieldStorage' => 'infrastructure/customfield/storage/PhabricatorCustomFieldStorage.php',
|
'PhabricatorCustomFieldStorage' => 'infrastructure/customfield/storage/PhabricatorCustomFieldStorage.php',
|
||||||
'PhabricatorCustomFieldStringIndexStorage' => 'infrastructure/customfield/storage/PhabricatorCustomFieldStringIndexStorage.php',
|
'PhabricatorCustomFieldStringIndexStorage' => 'infrastructure/customfield/storage/PhabricatorCustomFieldStringIndexStorage.php',
|
||||||
'PhabricatorDaemon' => 'infrastructure/daemon/PhabricatorDaemon.php',
|
'PhabricatorDaemon' => 'infrastructure/daemon/PhabricatorDaemon.php',
|
||||||
'PhabricatorDaemonCombinedLogController' => 'applications/daemon/controller/PhabricatorDaemonCombinedLogController.php',
|
|
||||||
'PhabricatorDaemonConsoleController' => 'applications/daemon/controller/PhabricatorDaemonConsoleController.php',
|
'PhabricatorDaemonConsoleController' => 'applications/daemon/controller/PhabricatorDaemonConsoleController.php',
|
||||||
'PhabricatorDaemonController' => 'applications/daemon/controller/PhabricatorDaemonController.php',
|
'PhabricatorDaemonController' => 'applications/daemon/controller/PhabricatorDaemonController.php',
|
||||||
'PhabricatorDaemonDAO' => 'applications/daemon/storage/PhabricatorDaemonDAO.php',
|
'PhabricatorDaemonDAO' => 'applications/daemon/storage/PhabricatorDaemonDAO.php',
|
||||||
|
@ -4214,7 +4213,6 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorCustomFieldStorage' => 'PhabricatorLiskDAO',
|
'PhabricatorCustomFieldStorage' => 'PhabricatorLiskDAO',
|
||||||
'PhabricatorCustomFieldStringIndexStorage' => 'PhabricatorCustomFieldIndexStorage',
|
'PhabricatorCustomFieldStringIndexStorage' => 'PhabricatorCustomFieldIndexStorage',
|
||||||
'PhabricatorDaemon' => 'PhutilDaemon',
|
'PhabricatorDaemon' => 'PhutilDaemon',
|
||||||
'PhabricatorDaemonCombinedLogController' => 'PhabricatorDaemonController',
|
|
||||||
'PhabricatorDaemonConsoleController' => 'PhabricatorDaemonController',
|
'PhabricatorDaemonConsoleController' => 'PhabricatorDaemonController',
|
||||||
'PhabricatorDaemonController' => 'PhabricatorController',
|
'PhabricatorDaemonController' => 'PhabricatorController',
|
||||||
'PhabricatorDaemonDAO' => 'PhabricatorLiskDAO',
|
'PhabricatorDaemonDAO' => 'PhabricatorLiskDAO',
|
||||||
|
|
|
@ -45,7 +45,6 @@ final class PhabricatorDaemonsApplication extends PhabricatorApplication {
|
||||||
=> 'PhabricatorWorkerTaskUpdateController',
|
=> 'PhabricatorWorkerTaskUpdateController',
|
||||||
'log/' => array(
|
'log/' => array(
|
||||||
'' => 'PhabricatorDaemonLogListController',
|
'' => 'PhabricatorDaemonLogListController',
|
||||||
'combined/' => 'PhabricatorDaemonCombinedLogController',
|
|
||||||
'(?P<id>[1-9]\d*)/' => 'PhabricatorDaemonLogViewController',
|
'(?P<id>[1-9]\d*)/' => 'PhabricatorDaemonLogViewController',
|
||||||
),
|
),
|
||||||
'event/(?P<id>[1-9]\d*)/' => 'PhabricatorDaemonLogEventViewController',
|
'event/(?P<id>[1-9]\d*)/' => 'PhabricatorDaemonLogEventViewController',
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
final class PhabricatorDaemonCombinedLogController
|
|
||||||
extends PhabricatorDaemonController {
|
|
||||||
|
|
||||||
|
|
||||||
public function processRequest() {
|
|
||||||
$request = $this->getRequest();
|
|
||||||
|
|
||||||
$pager = new AphrontPagerView();
|
|
||||||
$pager->setOffset($request->getInt('page'));
|
|
||||||
$pager->setPageSize(1000);
|
|
||||||
|
|
||||||
$events = id(new PhabricatorDaemonLogEvent())->loadAllWhere(
|
|
||||||
'1 = 1 ORDER BY id DESC LIMIT %d, %d',
|
|
||||||
$pager->getOffset(),
|
|
||||||
$pager->getPageSize() + 1);
|
|
||||||
|
|
||||||
$events = $pager->sliceResults($events);
|
|
||||||
$pager->setURI($request->getRequestURI(), 'page');
|
|
||||||
|
|
||||||
$event_view = new PhabricatorDaemonLogEventsView();
|
|
||||||
$event_view->setEvents($events);
|
|
||||||
$event_view->setUser($request->getUser());
|
|
||||||
$event_view->setCombinedLog(true);
|
|
||||||
|
|
||||||
$log_panel = new AphrontPanelView();
|
|
||||||
$log_panel->setHeader('Combined Daemon Logs');
|
|
||||||
$log_panel->appendChild($event_view);
|
|
||||||
$log_panel->appendChild($pager);
|
|
||||||
$log_panel->setNoBackground();
|
|
||||||
|
|
||||||
$nav = $this->buildSideNavView();
|
|
||||||
$nav->selectFilter('log/combined');
|
|
||||||
$nav->appendChild($log_panel);
|
|
||||||
|
|
||||||
return $this->buildApplicationPage(
|
|
||||||
$nav,
|
|
||||||
array(
|
|
||||||
'title' => pht('Combined Daemon Log'),
|
|
||||||
'device' => false,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -9,7 +9,6 @@ abstract class PhabricatorDaemonController extends PhabricatorController {
|
||||||
$nav->addLabel(pht('Daemons'));
|
$nav->addLabel(pht('Daemons'));
|
||||||
$nav->addFilter('/', pht('Console'));
|
$nav->addFilter('/', pht('Console'));
|
||||||
$nav->addFilter('log', pht('All Daemons'));
|
$nav->addFilter('log', pht('All Daemons'));
|
||||||
$nav->addFilter('log/combined', pht('Combined Log'));
|
|
||||||
|
|
||||||
return $nav;
|
return $nav;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,52 +6,62 @@ final class PhabricatorDaemonManagementLogWorkflow
|
||||||
public function didConstruct() {
|
public function didConstruct() {
|
||||||
$this
|
$this
|
||||||
->setName('log')
|
->setName('log')
|
||||||
->setExamples('**log** __id__')
|
->setExamples('**log** [__options__]')
|
||||||
->setSynopsis(
|
->setSynopsis(
|
||||||
pht(
|
pht(
|
||||||
'Print the log for a daemon, identified by ID. You can get the '.
|
'Print the logs for all daemons, or some daemon(s) identified by '.
|
||||||
'ID for a daemon from the Daemon Console in the web interface.'))
|
'ID. You can get the ID for a daemon from the Daemon Console in '.
|
||||||
|
'the web interface.'))
|
||||||
->setArguments(
|
->setArguments(
|
||||||
array(
|
array(
|
||||||
array(
|
array(
|
||||||
'name' => 'daemon',
|
'name' => 'id',
|
||||||
'wildcard' => true,
|
'param' => 'id',
|
||||||
|
'help' => 'Show logs for daemon(s) with given ID(s).',
|
||||||
|
'repeat' => true,
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'name' => 'limit',
|
||||||
|
'param' => 'N',
|
||||||
|
'default' => 100,
|
||||||
|
'help' => 'Show a specific number of log messages '.
|
||||||
|
'(default 100).',
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute(PhutilArgumentParser $args) {
|
public function execute(PhutilArgumentParser $args) {
|
||||||
$id = $args->getArg('daemon');
|
|
||||||
if (!$id) {
|
|
||||||
throw new PhutilArgumentUsageException(
|
|
||||||
pht('You must specify the daemon ID to show logs for.'));
|
|
||||||
} else if (count($id) > 1) {
|
|
||||||
throw new PhutilArgumentUsageException(
|
|
||||||
pht('Specify exactly one daemon ID to show logs for.'));
|
|
||||||
}
|
|
||||||
$id = head($id);
|
|
||||||
|
|
||||||
$daemon = id(new PhabricatorDaemonLogQuery())
|
$query = id(new PhabricatorDaemonLogQuery())
|
||||||
->setViewer($this->getViewer())
|
->setViewer($this->getViewer())
|
||||||
->withIDs(array($id))
|
->setAllowStatusWrites(true);
|
||||||
->setAllowStatusWrites(true)
|
$ids = $args->getArg('id');
|
||||||
->executeOne();
|
if ($ids) {
|
||||||
|
$query->withIDs($ids);
|
||||||
|
}
|
||||||
|
$daemons = $query->execute();
|
||||||
|
|
||||||
if (!$daemon) {
|
if (!$daemons) {
|
||||||
|
if ($ids) {
|
||||||
throw new PhutilArgumentUsageException(
|
throw new PhutilArgumentUsageException(
|
||||||
pht('No such daemon with id "%s"!', $id));
|
pht('No daemon(s) with id(s) "%s" exist!', implode(', ', $ids)));
|
||||||
|
} else {
|
||||||
|
throw new PhutilArgumentUsageException(
|
||||||
|
pht('No daemons are running.'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$console = PhutilConsole::getConsole();
|
$console = PhutilConsole::getConsole();
|
||||||
$logs = id(new PhabricatorDaemonLogEvent())->loadAllWhere(
|
$logs = id(new PhabricatorDaemonLogEvent())->loadAllWhere(
|
||||||
'logID = %d ORDER BY id ASC',
|
'logID IN (%Ld) ORDER BY id ASC',
|
||||||
$daemon->getID());
|
mpull($daemons, 'getID'));
|
||||||
|
|
||||||
$lines = array();
|
$lines = array();
|
||||||
foreach ($logs as $log) {
|
foreach ($logs as $log) {
|
||||||
$text_lines = phutil_split_lines($log->getMessage(), $retain = false);
|
$text_lines = phutil_split_lines($log->getMessage(), $retain = false);
|
||||||
foreach ($text_lines as $line) {
|
foreach ($text_lines as $line) {
|
||||||
$lines[] = array(
|
$lines[] = array(
|
||||||
|
'id' => $log->getLogID(),
|
||||||
'type' => $log->getLogType(),
|
'type' => $log->getLogType(),
|
||||||
'date' => $log->getEpoch(),
|
'date' => $log->getEpoch(),
|
||||||
'data' => $line,
|
'data' => $line,
|
||||||
|
@ -60,6 +70,7 @@ final class PhabricatorDaemonManagementLogWorkflow
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($lines as $line) {
|
foreach ($lines as $line) {
|
||||||
|
$id = $line['id'];
|
||||||
$type = $line['type'];
|
$type = $line['type'];
|
||||||
$data = $line['data'];
|
$data = $line['data'];
|
||||||
$date = date('r', $line['date']);
|
$date = date('r', $line['date']);
|
||||||
|
@ -67,9 +78,10 @@ final class PhabricatorDaemonManagementLogWorkflow
|
||||||
$console->writeOut(
|
$console->writeOut(
|
||||||
"%s\n",
|
"%s\n",
|
||||||
sprintf(
|
sprintf(
|
||||||
'[%s] %s %s',
|
'Daemon %d %s [%s] %s',
|
||||||
$date,
|
$id,
|
||||||
$type,
|
$type,
|
||||||
|
$date,
|
||||||
$data));
|
$data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,10 @@ abstract class PhabricatorBaseEnglishTranslation
|
||||||
|
|
||||||
public function getTranslations() {
|
public function getTranslations() {
|
||||||
return array(
|
return array(
|
||||||
|
'No daemon(s) with id(s) "%s" exist!' => array(
|
||||||
|
'No daemon with id %s exists!',
|
||||||
|
'No daemons with ids %s exist!',
|
||||||
|
),
|
||||||
'These %d configuration value(s) are related:' => array(
|
'These %d configuration value(s) are related:' => array(
|
||||||
'This configuration value is related:',
|
'This configuration value is related:',
|
||||||
'These configuration values are related:',
|
'These configuration values are related:',
|
||||||
|
|
Loading…
Reference in a new issue