Permalink
Browse files

Consolidate "live" debug into tail command.

  • Loading branch information...
taylorotwell committed Oct 21, 2013
1 parent 28e36bb commit f62d1a727155073357babee95a8f679003a8b93c
@@ -21,7 +21,6 @@
"patchwork/utf8": "1.1.*",
"phpseclib/phpseclib": "0.3.*",
"predis/predis": "0.8.*",
"react/socket": "0.3.*",
"swiftmailer/swiftmailer": "5.0.*",
"symfony/browser-kit": "2.4.*",
"symfony/console": "2.4.*",

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -1,6 +1,7 @@
<?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;
@@ -27,43 +28,118 @@ class TailCommand extends Command {
*/
public function fire()
{
$path = $this->getPath();
$path = $this->getPath($this->argument('connection'));
if ($path)
{
$output = $this->output;
$this->getConnection()->run('tail -f '.$path, function($line) use ($output)
{
$output->write($line);
});
$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)
{
$this->registerQueryLogger();
$output = $this->output;
with(new Process('tail -f '.$path))->run(function($type, $line) use ($output)
{
$output->write($line);
});
}
/**
* Register a query logger for local tailing convenience.
*
* @return void
*/
protected function registerQueryLogger()
{
$app = $this->laravel;
$this->laravel['db']->listen(function($sql, $bindings, $time) use ($app)
{
$sql = str_replace_array('\?', $bindings, $sql);
$app['log']->debug($sql.' ['.$time.'ms]');
});
}
/**
* 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;
$this->getRemote($connection)->run('tail -f '.$path, function($line) use ($out)
{
$out->write($line);
});
}
/**
* Get a connection to the remote server.
*
* @param string $connection
* @return \Illuminate\Remote\Connection
*/
protected function getConnection()
protected function getRemote($connection)
{
return $this->laravel['remote']->connection($this->argument('connection'));
return $this->laravel['remote']->connection($connection);
}
/**
* Get the path to the Laraevl log file.
*
* @param string $connection
* @return string
*/
protected function getPath()
protected function getPath($connection)
{
if ($this->option('path')) return $this->option('path');
return $this->getRoot($this->argument('connection')).'/app/storage/logs/laravel.log';
if (is_null($connection))
{
return base_path().'/app/storage/logs/laravel.log';
}
else
{
return $this->getRoot($connection).'/app/storage/logs/laravel.log';
}
}
/**
@@ -85,7 +161,7 @@ protected function getRoot($connection)
protected function getArguments()
{
return array(
array('connection', InputArgument::REQUIRED, 'The remote connection name'),
array('connection', InputArgument::OPTIONAL, 'The remote connection name'),
);
}

3 comments on commit f62d1a7

@codeforest

This comment has been minimized.

codeforest replied Oct 23, 2013

Hi guys,

after this commit I am getting an error on composer update:
$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Generating autoload files
{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Class 'Illuminate\Exception\Li
veServiceProvider' not found","file":"C:\wamp\www\laravel_tut\vendor\laravel\framework\src\Illuminate\Foundatio
n\ProviderRepository.php","line":123}}PHP Fatal error: Class 'Illuminate\Exception\LiveServiceProvider' not found in C
:\wamp\www\laravel_tut\vendor\laravel\framework\src\Illuminate\Foundation\ProviderRepository.php on line 123
PHP Stack trace:
PHP 1. {main}() C:\wamp\www\laravel_tut\artisan:0
PHP 2. require_once() C:\wamp\www\laravel_tut\artisan:30
PHP 3. require() C:\wamp\www\laravel_tut\bootstrap\start.php:61
PHP 4. Illuminate\Foundation\ProviderRepository->load() C:\wamp\www\laravel_tut\vendor\laravel\framework\src\Illuminat
e\Foundation\start.php:195
PHP 5. Illuminate\Foundation\ProviderRepository->createProvider() C:\wamp\www\laravel_tut\vendor\laravel\framework\src
\Illuminate\Foundation\ProviderRepository.php:67

Thanks

@taylorotwell

This comment has been minimized.

Member

taylorotwell replied Oct 23, 2013

Remove live service provider from your app providers.

@codeforest

This comment has been minimized.

codeforest replied Oct 23, 2013

Thanks Taylor...I was quick to post a comment, but then thought of this, too.

Please sign in to comment.