Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Console] Display errors in quiet mode #18781

Closed
wants to merge 6 commits into from

Conversation

multi-io
Copy link
Contributor

@multi-io multi-io commented May 13, 2016

Q A
Branch? 2.8
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #18767
License MIT
Doc PR
  • map VERBOSITY_QUIET normally, rather than suppressing all output
    without override
  • ensure that we do write to the output if we've determined (via
    verbosityLevelMap) that we should

About the second point, it seems ConsoleLogger has the same issue (https://github.com/symfony/symfony/blob/2.8/src/Symfony/Component/Console/Logger/ConsoleLogger.php#L92), but since we're not using that, I haven't checked it.

- map VERBOSITY_QUIET normally, rather than suppressing all output
  without override

- ensure that we do write to the output if we've determined (via
  verbosityLevelMap) that we should
@javiereguiluz javiereguiluz changed the title bug #18767 ConsoleHandler output handling fixed [Console] ConsoleHandler output handling fixed May 18, 2016
// (integration test for the issue #18767 fix)
$levelName = Logger::getLevelName($level);

$realOutput = $this->getMock('Symfony\Component\Console\Output\Output', ['doWrite']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array('doWrite')

@nicolas-grekas
Copy link
Member

nicolas-grekas commented May 19, 2016

@multi-io it would be cool if you could also look at fixing ConsoleLogger.php: let's not leave a bug that someone else will hit and spend time on, whereas it's cheap to fix now that we know about it :) thanks

@multi-io
Copy link
Contributor Author

@nicolas-grekas ok I've applied the fix to ConsoleLogger too. I've added a ConsoleLogger-specific test that would reproduce the fixed bug.

The "if" query condition in ConsoleLogger's output pipeline that compares input and output verbosity to determine whether the output should take place or not is actually redundant because the output will do the exact same thing internally. I guess it still makes sense to leave it in because it short-cuts and avoids formatting the output message in the case where we're not going to write it out anyway. But I've added a comment that at least documents this. We might want to remove the if query instead if we regard the small win in code clarity higher than the performance gain. :)

It may be advisable to change the default $verbosityLevelMap of ConsoleLogger so that errors and emergencies are output even to a VERBOSITY_QUIET output (which is used e.g. when running a Symfony command with -q -- quite a common thing, and you may not want to suppress all output there). But I'm not sure about Symfony's actual policy regarding this (if any), and it would technically be a breaking change, so I haven't done it.

Previously, ConsoleLogger would always output everything to its
backing output at the default verbosity (VERBOSITY_NORMAL), which
meant that if the output had its verbosity setting set to
VERBOSITY_QUIET, nothing would ever be output to it, even if the
ConsoleLogger's verbosityMap specified that some logging levels should
be output even to a VERBOSITY_QUIET output.
@nicolas-grekas nicolas-grekas changed the title [Console] ConsoleHandler output handling fixed [Console] Display errors in quiet mode Jun 8, 2016
@nicolas-grekas
Copy link
Member

👍, as a feature to me

@@ -55,12 +55,36 @@ public function testVerbosityMapping($verbosity, $level, $isHandling, array $map
$this->assertSame($isHandling, $handler->isHandling(array('level' => $level)),
'->isHandling returns correct value depending on console verbosity and log level'
);

//check that the handler actually outputs the record iff it handles it
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if instead of iff

@fabpot
Copy link
Member

fabpot commented Jun 8, 2016

👍 for master

@multi-io
Copy link
Contributor Author

multi-io commented Jun 9, 2016

Thanks for the review. If you don't mind, I'll rewrite the branch history to avoid multiple tiny style fix commits.

@fabpot
Copy link
Member

fabpot commented Jun 9, 2016

@multi-io You can squash the commits if you like but just to let you know, we can do it automatically when merging.

@multi-io
Copy link
Contributor Author

multi-io commented Jun 9, 2016

@fabpot ah, ok. I'll do style commits then.

@multi-io
Copy link
Contributor Author

multi-io commented Jun 9, 2016

Fixes pushed.

);
}

}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A carriage return must be added after }

@multi-io
Copy link
Contributor Author

multi-io commented Jun 9, 2016

Sorry, I guess I misunderstood your earlier description. This should be the right fix now.

@fabpot
Copy link
Member

fabpot commented Jun 10, 2016

Thank you @multi-io.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants