@@ 14-79 (lines=66) @@ | ||
11 | * Class StreamCommand |
|
12 | * @package Magestead\Command\Redis |
|
13 | */ |
|
14 | class StreamCommand extends Command |
|
15 | { |
|
16 | protected $_config; |
|
17 | protected $_projectPath; |
|
18 | ||
19 | /** |
|
20 | * Configure the stream command |
|
21 | */ |
|
22 | protected function configure() |
|
23 | { |
|
24 | $this->_projectPath = getcwd(); |
|
25 | $this->setName("log:stream"); |
|
26 | $this->setDescription("Stream a specific server log"); |
|
27 | $this->addArgument('log', InputArgument::REQUIRED, 'access or error'); |
|
28 | } |
|
29 | ||
30 | /** |
|
31 | * @param InputInterface $input |
|
32 | * @param OutputInterface $output |
|
33 | * @return ProcessCommand |
|
34 | */ |
|
35 | protected function execute(InputInterface $input, OutputInterface $output) |
|
36 | { |
|
37 | $log = $input->getArgument('log'); |
|
38 | ||
39 | $output->writeln('<info>Streaming '. ucwords($log) . ' Log</info>'); |
|
40 | $command = $this->getCommand(new Config($output), $log); |
|
41 | if (!$command) { |
|
42 | return $output->writeln('<error>Command not available for this application</error>'); |
|
43 | } |
|
44 | ||
45 | $pCommand = "vagrant ssh -c '". $command ."'"; |
|
46 | return new ProcessCommand($pCommand, $this->_projectPath, $output); |
|
47 | } |
|
48 | ||
49 | /** |
|
50 | * @param Config $config |
|
51 | * @param $log |
|
52 | * @return string |
|
53 | */ |
|
54 | private function getCommand(Config $config, $log) |
|
55 | { |
|
56 | $server = $config->_config['magestead']['server']; |
|
57 | $os = $config->_config['magestead']['os']; |
|
58 | ||
59 | $location = $this->getLogLocation($server, $os); |
|
60 | $command = 'tail -f /var/log/' . $location . '/' . $config->base_url . '-' . $log . '.log'; |
|
61 | ||
62 | return $command; |
|
63 | } |
|
64 | ||
65 | /** |
|
66 | * @param $server |
|
67 | * @param $os |
|
68 | * @return string |
|
69 | */ |
|
70 | private function getLogLocation($server, $os) |
|
71 | { |
|
72 | $location = 'nginx'; |
|
73 | if ($server != 'nginx') { |
|
74 | $location = ($os == 'ubuntu14') ? 'apache2' : 'httpd'; |
|
75 | } |
|
76 | ||
77 | return $location; |
|
78 | } |
|
79 | } |
|
80 |
@@ 14-79 (lines=66) @@ | ||
11 | * Class ViewCommand |
|
12 | * @package Magestead\Command\Redis |
|
13 | */ |
|
14 | class ViewCommand extends Command |
|
15 | { |
|
16 | protected $_config; |
|
17 | protected $_projectPath; |
|
18 | ||
19 | /** |
|
20 | * Configure the view command |
|
21 | */ |
|
22 | protected function configure() |
|
23 | { |
|
24 | $this->_projectPath = getcwd(); |
|
25 | $this->setName("log:view"); |
|
26 | $this->setDescription("View a specific server log"); |
|
27 | $this->addArgument('log', InputArgument::REQUIRED, 'access or error'); |
|
28 | } |
|
29 | ||
30 | /** |
|
31 | * @param InputInterface $input |
|
32 | * @param OutputInterface $output |
|
33 | * @return ProcessCommand |
|
34 | */ |
|
35 | protected function execute(InputInterface $input, OutputInterface $output) |
|
36 | { |
|
37 | $log = $input->getArgument('log'); |
|
38 | ||
39 | $output->writeln('<info>Viewing '. ucwords($log) . ' Log</info>'); |
|
40 | $command = $this->getCommand(new Config($output), $log); |
|
41 | if (!$command) { |
|
42 | return $output->writeln('<error>Command not available for this application</error>'); |
|
43 | } |
|
44 | ||
45 | $pCommand = "vagrant ssh -c '". $command ."'"; |
|
46 | return new ProcessCommand($pCommand, $this->_projectPath, $output); |
|
47 | } |
|
48 | ||
49 | /** |
|
50 | * @param Config $config |
|
51 | * @param $log |
|
52 | * @return string |
|
53 | */ |
|
54 | private function getCommand(Config $config, $log) |
|
55 | { |
|
56 | $server = $config->_config['magestead']['server']; |
|
57 | $os = $config->_config['magestead']['os']; |
|
58 | ||
59 | $location = $this->getLogLocation($server, $os); |
|
60 | $command = 'cat /var/log/' . $location . '/' . $config->base_url . '-' . $log . '.log'; |
|
61 | ||
62 | return $command; |
|
63 | } |
|
64 | ||
65 | /** |
|
66 | * @param $server |
|
67 | * @param $os |
|
68 | * @return string |
|
69 | */ |
|
70 | private function getLogLocation($server, $os) |
|
71 | { |
|
72 | $location = 'nginx'; |
|
73 | if ($server != 'nginx') { |
|
74 | $location = ($os == 'ubuntu14') ? 'apache2' : 'httpd'; |
|
75 | } |
|
76 | ||
77 | return $location; |
|
78 | } |
|
79 | } |
|
80 |