From 06882a99cf924ef3cbe780dfdfcd26da06c7d7e1 Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Wed, 27 Aug 2014 14:53:38 -0700 Subject: [PATCH] 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 --- src/__phutil_library_map__.php | 2 - .../PhabricatorDaemonsApplication.php | 1 - ...PhabricatorDaemonCombinedLogController.php | 45 -------------- .../PhabricatorDaemonController.php | 1 - ...PhabricatorDaemonManagementLogWorkflow.php | 62 +++++++++++-------- .../PhabricatorBaseEnglishTranslation.php | 4 ++ 6 files changed, 41 insertions(+), 74 deletions(-) delete mode 100644 src/applications/daemon/controller/PhabricatorDaemonCombinedLogController.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 8f5b7d061a..3c4b3d25a7 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1375,7 +1375,6 @@ phutil_register_library_map(array( 'PhabricatorCustomFieldStorage' => 'infrastructure/customfield/storage/PhabricatorCustomFieldStorage.php', 'PhabricatorCustomFieldStringIndexStorage' => 'infrastructure/customfield/storage/PhabricatorCustomFieldStringIndexStorage.php', 'PhabricatorDaemon' => 'infrastructure/daemon/PhabricatorDaemon.php', - 'PhabricatorDaemonCombinedLogController' => 'applications/daemon/controller/PhabricatorDaemonCombinedLogController.php', 'PhabricatorDaemonConsoleController' => 'applications/daemon/controller/PhabricatorDaemonConsoleController.php', 'PhabricatorDaemonController' => 'applications/daemon/controller/PhabricatorDaemonController.php', 'PhabricatorDaemonDAO' => 'applications/daemon/storage/PhabricatorDaemonDAO.php', @@ -4214,7 +4213,6 @@ phutil_register_library_map(array( 'PhabricatorCustomFieldStorage' => 'PhabricatorLiskDAO', 'PhabricatorCustomFieldStringIndexStorage' => 'PhabricatorCustomFieldIndexStorage', 'PhabricatorDaemon' => 'PhutilDaemon', - 'PhabricatorDaemonCombinedLogController' => 'PhabricatorDaemonController', 'PhabricatorDaemonConsoleController' => 'PhabricatorDaemonController', 'PhabricatorDaemonController' => 'PhabricatorController', 'PhabricatorDaemonDAO' => 'PhabricatorLiskDAO', diff --git a/src/applications/daemon/application/PhabricatorDaemonsApplication.php b/src/applications/daemon/application/PhabricatorDaemonsApplication.php index e51bba8f4a..52b6586a40 100644 --- a/src/applications/daemon/application/PhabricatorDaemonsApplication.php +++ b/src/applications/daemon/application/PhabricatorDaemonsApplication.php @@ -45,7 +45,6 @@ final class PhabricatorDaemonsApplication extends PhabricatorApplication { => 'PhabricatorWorkerTaskUpdateController', 'log/' => array( '' => 'PhabricatorDaemonLogListController', - 'combined/' => 'PhabricatorDaemonCombinedLogController', '(?P[1-9]\d*)/' => 'PhabricatorDaemonLogViewController', ), 'event/(?P[1-9]\d*)/' => 'PhabricatorDaemonLogEventViewController', diff --git a/src/applications/daemon/controller/PhabricatorDaemonCombinedLogController.php b/src/applications/daemon/controller/PhabricatorDaemonCombinedLogController.php deleted file mode 100644 index 8a8fcc0e59..0000000000 --- a/src/applications/daemon/controller/PhabricatorDaemonCombinedLogController.php +++ /dev/null @@ -1,45 +0,0 @@ -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, - )); - } - -} diff --git a/src/applications/daemon/controller/PhabricatorDaemonController.php b/src/applications/daemon/controller/PhabricatorDaemonController.php index fda0ec24a7..24fbceb710 100644 --- a/src/applications/daemon/controller/PhabricatorDaemonController.php +++ b/src/applications/daemon/controller/PhabricatorDaemonController.php @@ -9,7 +9,6 @@ abstract class PhabricatorDaemonController extends PhabricatorController { $nav->addLabel(pht('Daemons')); $nav->addFilter('/', pht('Console')); $nav->addFilter('log', pht('All Daemons')); - $nav->addFilter('log/combined', pht('Combined Log')); return $nav; } diff --git a/src/applications/daemon/management/PhabricatorDaemonManagementLogWorkflow.php b/src/applications/daemon/management/PhabricatorDaemonManagementLogWorkflow.php index 4c65c74e8f..a2b8852550 100644 --- a/src/applications/daemon/management/PhabricatorDaemonManagementLogWorkflow.php +++ b/src/applications/daemon/management/PhabricatorDaemonManagementLogWorkflow.php @@ -6,52 +6,62 @@ final class PhabricatorDaemonManagementLogWorkflow public function didConstruct() { $this ->setName('log') - ->setExamples('**log** __id__') + ->setExamples('**log** [__options__]') ->setSynopsis( pht( - 'Print the log for a daemon, identified by ID. You can get the '. - 'ID for a daemon from the Daemon Console in the web interface.')) + 'Print the logs for all daemons, or some daemon(s) identified by '. + 'ID. You can get the ID for a daemon from the Daemon Console in '. + 'the web interface.')) ->setArguments( array( array( - 'name' => 'daemon', - 'wildcard' => true, + 'name' => 'id', + '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) { - $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()) - ->withIDs(array($id)) - ->setAllowStatusWrites(true) - ->executeOne(); + ->setAllowStatusWrites(true); + $ids = $args->getArg('id'); + if ($ids) { + $query->withIDs($ids); + } + $daemons = $query->execute(); - if (!$daemon) { - throw new PhutilArgumentUsageException( - pht('No such daemon with id "%s"!', $id)); + if (!$daemons) { + if ($ids) { + throw new PhutilArgumentUsageException( + pht('No daemon(s) with id(s) "%s" exist!', implode(', ', $ids))); + } else { + throw new PhutilArgumentUsageException( + pht('No daemons are running.')); + } } $console = PhutilConsole::getConsole(); $logs = id(new PhabricatorDaemonLogEvent())->loadAllWhere( - 'logID = %d ORDER BY id ASC', - $daemon->getID()); + 'logID IN (%Ld) ORDER BY id ASC', + mpull($daemons, 'getID')); $lines = array(); foreach ($logs as $log) { $text_lines = phutil_split_lines($log->getMessage(), $retain = false); foreach ($text_lines as $line) { $lines[] = array( + 'id' => $log->getLogID(), 'type' => $log->getLogType(), 'date' => $log->getEpoch(), 'data' => $line, @@ -60,6 +70,7 @@ final class PhabricatorDaemonManagementLogWorkflow } foreach ($lines as $line) { + $id = $line['id']; $type = $line['type']; $data = $line['data']; $date = date('r', $line['date']); @@ -67,9 +78,10 @@ final class PhabricatorDaemonManagementLogWorkflow $console->writeOut( "%s\n", sprintf( - '[%s] %s %s', - $date, + 'Daemon %d %s [%s] %s', + $id, $type, + $date, $data)); } diff --git a/src/infrastructure/internationalization/translation/PhabricatorBaseEnglishTranslation.php b/src/infrastructure/internationalization/translation/PhabricatorBaseEnglishTranslation.php index d717a780ae..2689ec0efe 100644 --- a/src/infrastructure/internationalization/translation/PhabricatorBaseEnglishTranslation.php +++ b/src/infrastructure/internationalization/translation/PhabricatorBaseEnglishTranslation.php @@ -9,6 +9,10 @@ abstract class PhabricatorBaseEnglishTranslation public function getTranslations() { 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( 'This configuration value is related:', 'These configuration values are related:',