-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLogstreamCommand.php
98 lines (87 loc) · 3.05 KB
/
LogstreamCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
namespace AcquiaLogstream;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use AcquiaCloudApi\Connector\Client;
use AcquiaCloudApi\Connector\Connector;
use AcquiaCloudApi\Endpoints\Logs;
/**
* Class AcquiaLogstream
*
* @package AcquiaLogstream
*/
class LogstreamCommand extends Command
{
protected static $defaultName = 'acquia:logstream';
/**
* @inheritdoc
*/
protected function configure()
{
$this
->setAliases(['logstream', 'stream'])
->setDescription('Streams logs directly from the Acquia Cloud')
->addArgument('key', InputArgument::REQUIRED, 'Acquia API key')
->addArgument('secret', InputArgument::REQUIRED, 'Acquia API secret')
->addArgument('environmentUuid', InputArgument::REQUIRED, 'UUID of the environment to stream')
->addOption(
'logtypes',
't',
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
'Log types to stream',
[
'bal-request',
'varnish-request',
'apache-request',
'apache-error',
'php-error',
'drupal-watchdog',
'drupal-request',
'mysql-slow'
]
)
->addOption(
'servers',
's',
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
'Servers to stream logs from e.g. web-1234.'
)
->addOption(
'colourise',
'c',
InputOption::VALUE_NONE,
'Colorise the output based on HTTP status code.'
);
}
/**
* @inheritdoc
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$config = [
'key' => $input->getArgument('key'),
'secret' => $input->getArgument('secret')
];
$connector = new Connector($config);
$client = Client::factory($connector);
$client->addOption('headers', [
'User-Agent' => sprintf(
"%s/%s (https://github.com/typhonius/acquia-logstream)",
$this->getApplication()->getName(),
$this->getApplication()->getVersion()
)
]);
$logs = new Logs($client);
$stream = $logs->stream($input->getArgument('environmentUuid'));
$logstream = new LogstreamManager($input, $output);
$logstream->setParams($stream->logstream->params);
$logstream->setLogTypeFilter($input->getOption('logtypes'));
$logstream->setLogServerFilter($input->getOption('servers'));
$logstream->setColourise($input->getOption('colourise'));
$logstream->stream();
return 0;
}
}