feature #19174 [FrameworkBundle] Show server:run logs by default (nicolas-grekas)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[FrameworkBundle] Show server:run logs by default

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

I propose to change the default for the `server:run` command and show `php -S` logs by default.
I really miss them otherwise. The `-vvv` mode is not suited here, because it adds a useless ` ERR ` red prefix.
I do this through a tty when available, so that the output remains colored.

Ping @javiereguiluz @weaverryan since this is mostly a DX issue.

Commits
-------

7cc6161 [FrameworkBundle] Show server:run logs by default
This commit is contained in:
Fabien Potencier 2016-06-30 09:45:17 +02:00
commit 3282d5fb07

View File

@ -15,9 +15,12 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\ProcessBuilder;
use Symfony\Component\Process\Exception\RuntimeException;
/**
* Runs Symfony application using PHP built-in web server.
@ -113,14 +116,23 @@ EOF
$builder->setWorkingDirectory($documentRoot);
$builder->setTimeout(null);
$process = $builder->getProcess();
$callback = null;
if (OutputInterface::VERBOSITY_VERBOSE > $output->getVerbosity()) {
if (OutputInterface::VERBOSITY_NORMAL > $output->getVerbosity()) {
$process->disableOutput();
} else {
try {
$process->setTty(true);
} catch (RuntimeException $e) {
$callback = function ($type, $buffer) use ($output) {
if (Process::ERR === $type && $output instanceof ConsoleOutputInterface) {
$output = $output->getErrorOutput();
}
$output->write($buffer, false, OutputInterface::OUTPUT_RAW);
};
}
}
$this
->getHelper('process')
->run($output, $process, null, null, OutputInterface::VERBOSITY_VERBOSE);
$process->run($callback);
if (!$process->isSuccessful()) {
$errorMessages = array('Built-in server terminated unexpectedly.');