Skip to content

Commit 3282d5f

Browse files
committed
feature symfony#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
2 parents d870753 + 7cc6161 commit 3282d5f

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
use Symfony\Component\Console\Input\InputOption;
1616
use Symfony\Component\Console\Input\InputInterface;
1717
use Symfony\Component\Console\Output\OutputInterface;
18+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
1819
use Symfony\Component\Console\Style\SymfonyStyle;
1920
use Symfony\Component\Process\PhpExecutableFinder;
21+
use Symfony\Component\Process\Process;
2022
use Symfony\Component\Process\ProcessBuilder;
23+
use Symfony\Component\Process\Exception\RuntimeException;
2124

2225
/**
2326
* Runs Symfony application using PHP built-in web server.
@@ -113,14 +116,23 @@ protected function execute(InputInterface $input, OutputInterface $output)
113116
$builder->setWorkingDirectory($documentRoot);
114117
$builder->setTimeout(null);
115118
$process = $builder->getProcess();
119+
$callback = null;
116120

117-
if (OutputInterface::VERBOSITY_VERBOSE > $output->getVerbosity()) {
121+
if (OutputInterface::VERBOSITY_NORMAL > $output->getVerbosity()) {
118122
$process->disableOutput();
123+
} else {
124+
try {
125+
$process->setTty(true);
126+
} catch (RuntimeException $e) {
127+
$callback = function ($type, $buffer) use ($output) {
128+
if (Process::ERR === $type && $output instanceof ConsoleOutputInterface) {
129+
$output = $output->getErrorOutput();
130+
}
131+
$output->write($buffer, false, OutputInterface::OUTPUT_RAW);
132+
};
133+
}
119134
}
120-
121-
$this
122-
->getHelper('process')
123-
->run($output, $process, null, null, OutputInterface::VERBOSITY_VERBOSE);
135+
$process->run($callback);
124136

125137
if (!$process->isSuccessful()) {
126138
$errorMessages = array('Built-in server terminated unexpectedly.');

0 commit comments

Comments
 (0)