Subversion Repository Public Repository

Nextrek

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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php namespace Illuminate\Foundation\Console;

use Illuminate\Console\Command;
use Symfony\Component\Process\Process;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class TailCommand extends Command {

	/**
	 * The console command name.
	 *
	 * @var string
	 */
	protected $name = 'tail';

	/**
	 * The console command description.
	 *
	 * @var string
	 */
	protected $description = "Tail a log file on a remote server";

	/**
	 * Execute the console command.
	 *
	 * @return void
	 */
	public function fire()
	{
		$path = $this->getPath($this->argument('connection'));

		if ($path)
		{
			$this->tailLogFile($path, $this->argument('connection'));
		}
		else
		{
			$this->error('Could not determine path to log file.');
		}
	}

	/**
	 * Tail the given log file for the connection.
	 *
	 * @param  string  $path
	 * @param  string  $connection
	 * @return void
	 */
	protected function tailLogFile($path, $connection)
	{
		if (is_null($connection))
		{
			$this->tailLocalLogs($path);
		}
		else
		{
			$this->tailRemoteLogs($path, $connection);
		}
	}

	/**
	 * Tail a local log file for the application.
	 *
	 * @param  string  $path
	 * @return string
	 */
	protected function tailLocalLogs($path)
	{
		$output = $this->output;

		$lines = $this->option('lines');

		(new Process('tail -f -n '.$lines.' '.escapeshellarg($path)))->setTimeout(null)->run(function($type, $line) use ($output)
		{
			$output->write($line);
		});
	}

	/**
	 * Tail a remote log file at the given path and connection.
	 *
	 * @param  string  $path
	 * @param  string  $connection
	 * @return void
	 */
	protected function tailRemoteLogs($path, $connection)
	{
		$out = $this->output;

		$lines = $this->option('lines');

		$this->getRemote($connection)->run('tail -f -n '.$lines.' '.escapeshellarg($path), function($line) use ($out)
		{
			$out->write($line);
		});
	}

	/**
	 * Get a connection to the remote server.
	 *
	 * @param  string  $connection
	 * @return \Illuminate\Remote\Connection
	 */
	protected function getRemote($connection)
	{
		return $this->laravel['remote']->connection($connection);
	}

	/**
	 * Get the path to the Laravel log file.
	 *
	 * @param  string  $connection
	 * @return string
	 */
	protected function getPath($connection)
	{
		if ($this->option('path')) return $this->option('path');

		if (is_null($connection))
		{
			return storage_path('/logs/laravel.log');
		}

		return $this->getRoot($connection).str_replace(base_path(), '', storage_path()).'/logs/laravel.log';
	}

	/**
	 * Get the path to the Laravel install root.
	 *
	 * @param  string  $connection
	 * @return string
	 */
	protected function getRoot($connection)
	{
		return $this->laravel['config']['remote.connections.'.$connection.'.root'];
	}

	/**
	 * Get the console command arguments.
	 *
	 * @return array
	 */
	protected function getArguments()
	{
		return array(
			array('connection', InputArgument::OPTIONAL, 'The remote connection name'),
		);
	}

	/**
	 * Get the console command options.
	 *
	 * @return array
	 */
	protected function getOptions()
	{
		return array(
			array('path', null, InputOption::VALUE_OPTIONAL, 'The fully qualified path to the log file.'),

			array('lines', null, InputOption::VALUE_OPTIONAL, 'The number of lines to tail.', 20),
		);
	}

}

Commits for Nextrek/Aiba_backup/vendor/laravel/framework/src/Illuminate/Foundation/Console/TailCommand.php

Diff revisions: vs.
Revision Author Commited Message
1464 MOliva picture MOliva Tue 13 Oct, 2020 11:16:56 +0000