mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-25 08:12:40 +01:00
Add bin/phd log <id>
to dump all logs to the CLI
Summary: Ref T3557. Make it easier to access full daemon logs from the CLI. Test Plan: {F51265} Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T3557 Differential Revision: https://secure.phabricator.com/D6547
This commit is contained in:
parent
36c1359230
commit
88530ba053
4 changed files with 86 additions and 0 deletions
|
@ -23,6 +23,7 @@ $workflows = array(
|
|||
new PhabricatorDaemonManagementRestartWorkflow(),
|
||||
new PhabricatorDaemonManagementLaunchWorkflow(),
|
||||
new PhabricatorDaemonManagementDebugWorkflow(),
|
||||
new PhabricatorDaemonManagementLogWorkflow(),
|
||||
new PhutilHelpArgumentWorkflow(),
|
||||
);
|
||||
|
||||
|
|
|
@ -1032,6 +1032,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorDaemonManagementDebugWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementDebugWorkflow.php',
|
||||
'PhabricatorDaemonManagementLaunchWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementLaunchWorkflow.php',
|
||||
'PhabricatorDaemonManagementListWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementListWorkflow.php',
|
||||
'PhabricatorDaemonManagementLogWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementLogWorkflow.php',
|
||||
'PhabricatorDaemonManagementRestartWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementRestartWorkflow.php',
|
||||
'PhabricatorDaemonManagementStartWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementStartWorkflow.php',
|
||||
'PhabricatorDaemonManagementStatusWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementStatusWorkflow.php',
|
||||
|
@ -3039,6 +3040,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorDaemonManagementDebugWorkflow' => 'PhabricatorDaemonManagementWorkflow',
|
||||
'PhabricatorDaemonManagementLaunchWorkflow' => 'PhabricatorDaemonManagementWorkflow',
|
||||
'PhabricatorDaemonManagementListWorkflow' => 'PhabricatorDaemonManagementWorkflow',
|
||||
'PhabricatorDaemonManagementLogWorkflow' => 'PhabricatorDaemonManagementWorkflow',
|
||||
'PhabricatorDaemonManagementRestartWorkflow' => 'PhabricatorDaemonManagementWorkflow',
|
||||
'PhabricatorDaemonManagementStartWorkflow' => 'PhabricatorDaemonManagementWorkflow',
|
||||
'PhabricatorDaemonManagementStatusWorkflow' => 'PhabricatorDaemonManagementWorkflow',
|
||||
|
|
|
@ -91,6 +91,7 @@ final class PhabricatorDaemonLogViewController
|
|||
$view = id(new PhabricatorPropertyListView())
|
||||
->setUser($viewer);
|
||||
|
||||
$id = $daemon->getID();
|
||||
$c_epoch = $daemon->getDateCreated();
|
||||
$u_epoch = $daemon->getDateModified();
|
||||
|
||||
|
@ -165,6 +166,13 @@ final class PhabricatorDaemonLogViewController
|
|||
),
|
||||
$argv));
|
||||
|
||||
$view->addProperty(
|
||||
pht('View Full Logs'),
|
||||
phutil_tag(
|
||||
'tt',
|
||||
array(),
|
||||
"phabricator/ $ ./bin/phd log {$id}"));
|
||||
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorDaemonManagementLogWorkflow
|
||||
extends PhabricatorDaemonManagementWorkflow {
|
||||
|
||||
public function didConstruct() {
|
||||
$this
|
||||
->setName('log')
|
||||
->setSynopsis(pht('Print the log for a daemon.'))
|
||||
->setArguments(
|
||||
array(
|
||||
array(
|
||||
'name' => 'daemon',
|
||||
'wildcard' => true,
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
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())
|
||||
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||
->withIDs(array($id))
|
||||
->executeOne();
|
||||
|
||||
if (!$daemon) {
|
||||
throw new PhutilArgumentUsageException(
|
||||
pht('No such daemon with id "%s"!', $id));
|
||||
}
|
||||
|
||||
$console = PhutilConsole::getConsole();
|
||||
$logs = id(new PhabricatorDaemonLogEvent())->loadAllWhere(
|
||||
'logID = %d ORDER BY id ASC',
|
||||
$daemon->getID());
|
||||
|
||||
$lines = array();
|
||||
foreach ($logs as $log) {
|
||||
$text_lines = phutil_split_lines($log->getMessage(), $retain = false);
|
||||
foreach ($text_lines as $line) {
|
||||
$lines[] = array(
|
||||
'type' => $log->getLogType(),
|
||||
'date' => $log->getEpoch(),
|
||||
'data' => $line,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$type = $line['type'];
|
||||
$data = $line['data'];
|
||||
$date = date('r', $line['date']);
|
||||
|
||||
$console->writeOut(
|
||||
"%s\n",
|
||||
sprintf(
|
||||
'[%s] %s %s',
|
||||
$date,
|
||||
$type,
|
||||
$data));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue