Permalink
Browse files

Work on remote tail command.

  • Loading branch information...
taylorotwell committed Oct 20, 2013
1 parent 38d4e57 commit 25b1cac27080641b289c2ad791b734efff92bcef
@@ -0,0 +1,102 @@
<?php namespace Illuminate\Foundation\Console;
use Illuminate\Console\Command;
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();
if ($path)
{
$this->connection()->run('tail -f '.$path, function($out)
{
$this->line($out);
});
}
else
{
$this->error('Could not determine path to log file.');
}
}
/**
* Get a connection to the remote server.
*
* @return \Illuminate\Remote\Connection
*/
protected function getConnection()
{
return $this->laravel['remote']->connection($this->argument('connection'));
}
/**
* Get the path to the Laraevl log file.
*
* @return string
*/
protected function getPath()
{
if ($this->option('path')) return $this->option('path');
return $this->getRoot($this->argument('connection')).'/app/storage/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::REQUIRED, '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.'),
);
}
}
@@ -2,6 +2,7 @@
use Illuminate\Foundation\Artisan;
use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\Console\TailCommand;
use Illuminate\Foundation\Console\ChangesCommand;
use Illuminate\Foundation\Console\EnvironmentCommand;
@@ -26,6 +27,11 @@ public function register()
return new Artisan($app);
});
$this->app['command.tail'] = $this->app->share(function($app)
{
return new TailCommand;
});
$this->app['command.changes'] = $this->app->share(function($app)
{
return new ChangesCommand;
@@ -36,7 +42,7 @@ public function register()
return new EnvironmentCommand;
});
$this->commands('command.changes', 'command.environment');
$this->commands('command.tail', 'command.changes', 'command.environment');
}
/**

0 comments on commit 25b1cac

Please sign in to comment.