You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, apologies if this isn't a bug but some misconfiguration. I tried my best to isolate it however.
Problem
While using multiple progress bars, as shown in the docs, one has to use sections. This produces an expected result. However, when using logging alongside some logs (ref (b) in code) will be swallowed:
The solution I tracked down is to ensure logs (more specifically \Symfony\Bridge\Monolog\Handler\ConsoleHandler) uses a section above progress bars sections. This entails something I'm not 100% comfortable with - injecting monolog.handler.console and doing a manual ->setOutput() on it (ref (a) in code).
This produces almost correct result with no output being swallowed, but with extra spacing between log lines:
As you can see the issue seems to be caused by a combination of console's ConsoleSectionOutput & monolog's bridge ConsoleHandler. I was trying to debug it further but I got stuck.
How to reproduce
<?phpnamespaceApp\Command;
usePsr\Log\LoggerInterface;
useSymfony\Bridge\Monolog\Handler\ConsoleHandler;
useSymfony\Component\Console\Attribute\AsCommand;
useSymfony\Component\Console\Command\Command;
useSymfony\Component\Console\Helper\ProgressBar;
useSymfony\Component\Console\Input\InputInterface;
useSymfony\Component\Console\Output\OutputInterface;
useSymfony\Component\DependencyInjection\Attribute\Autowire;
#[AsCommand(name: 'app:test',)]
class TestCommand extends Command
{
publicfunction__construct(
privateLoggerInterface$log,
#[Autowire(service: 'monolog.handler.console')] privateConsoleHandler$consoleHandler
) {
parent::__construct();
}
protectedfunctionexecute(InputInterface$input, OutputInterface$output): int
{
//Without this the output of some logs will be swallowed once progress bars start rendering$this->consoleHandler->setOutput($output->section()); //ref. (a)//Example adapted from https://symfony.com/doc/current/components/console/helpers/progressbar.html#displaying-multiple-progress-bars$section1 = $output->section();
$section2 = $output->section();
$progress1 = newProgressBar($section1);
$progress2 = newProgressBar($section2);
$progress1->start(1000);
$progress2->start(1000);
$i = 0;
while (++$i < 1000) {
$progress1->advance();
if ($i % 2 === 0) {
$progress2->advance(4);
}
if ($i % 10 === 0) {
$this->log->warning('Hello ' . $i); //ref. (b)
}
usleep(5000);
}
return Command::SUCCESS;
}
}
Symfony version(s) affected
6.2.10
Description
First of all, apologies if this isn't a bug but some misconfiguration. I tried my best to isolate it however.
Problem
While using multiple progress bars, as shown in the docs, one has to use sections. This produces an expected result. However, when using logging alongside some logs (
ref (b)in code) will be swallowed:normal-log-and-bars.mov
Fixing the logs breaks sections spacing
The solution I tracked down is to ensure logs (more specifically
\Symfony\Bridge\Monolog\Handler\ConsoleHandler) uses a section above progress bars sections. This entails something I'm not 100% comfortable with - injectingmonolog.handler.consoleand doing a manual->setOutput()on it (ref (a)in code).This produces almost correct result with no output being swallowed, but with extra spacing between log lines:
section-log-and-bars.mov
Issue with
monolog-bridge+ section?I ran two more tests: normal logs (no
->setOutput($section)override) and logs in section but without bars.section-log-no-bars.mov
normal-log-no-bars.mov
As you can see the issue seems to be caused by a combination of console's
ConsoleSectionOutput& monolog's bridgeConsoleHandler. I was trying to debug it further but I got stuck.How to reproduce
Possible Solution
No response
Additional Context
No response