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;
}
}
Possible Solution
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered:
…s with a new line in section output (joelwurtz)
This PR was merged into the 6.3 branch.
Discussion
----------
[Console] avoid multiple new line when message already ends with a new line in section output
| Q | A
| ------------- | ---
| Branch? | 6.3
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | #50382
| License | MIT
| Doc PR |
When we write to the section with a new line in the message it ends up adding a double new line, it can be easily seen when we set a section as a console handler for the logs, each line of log will have a double new line ending adding a lot of noise.
I began to fix the implementation to correctly handle this case, but with all the logic of the max height and other stuff it appears to be way more complicated.
Simulating this case by removing the new line at the end of the message and recalling the write function with the newline parameter to true was way easier and avoid too many headcache when looking at the code.
Should fix#50382
Commits
-------
1f20f72 fix(console): avoid multiple new line when message already ends with a new line
…s with a new line in section output (joelwurtz)
This PR was merged into the 6.3 branch.
Discussion
----------
[Console] avoid multiple new line when message already ends with a new line in section output
| Q | A
| ------------- | ---
| Branch? | 6.3
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | symfony/symfony#50382
| License | MIT
| Doc PR |
When we write to the section with a new line in the message it ends up adding a double new line, it can be easily seen when we set a section as a console handler for the logs, each line of log will have a double new line ending adding a lot of noise.
I began to fix the implementation to correctly handle this case, but with all the logic of the max height and other stuff it appears to be way more complicated.
Simulating this case by removing the new line at the end of the message and recalling the write function with the newline parameter to true was way easier and avoid too many headcache when looking at the code.
Should fixsymfony/symfony#50382
Commits
-------
1f20f72640 fix(console): avoid multiple new line when message already ends with a new line
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.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:
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
The text was updated successfully, but these errors were encountered: