Skip to content

[Debug] Add BufferingLogger for errors that happen before a proper logger is configured #15521

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

Merged
merged 1 commit into from
Sep 10, 2015

Conversation

nicolas-grekas
Copy link
Member

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

This allows catching e.g. deprecations that happen during bootstrapping.

*
* @author Nicolas Grekas <p@tchwork.com>
*/
class BootstrappingLogger extends AbstractLogger
Copy link
Member

Choose a reason for hiding this comment

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

BootstrappingLogger does not make sense IMO. This logger has nothing specific to bootstrapping. It is a BufferLogger

Copy link
Member Author

Choose a reason for hiding this comment

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

It's more than a BufferLogger because it has a special behavior in ErrorHandler, this is what makes it a BootstrappingLogger IMO

Copy link
Member

Choose a reason for hiding this comment

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

well, the logger itself is not aware of this behavior. You could reuse it for what you want

Copy link
Member Author

Choose a reason for hiding this comment

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

renamed

@nicolas-grekas nicolas-grekas force-pushed the debug-boot branch 3 times, most recently from 500668d to 1ae2789 Compare August 12, 2015 14:36
@nicolas-grekas nicolas-grekas changed the title [Debug] Add BootstrappingLogger to buffer errors that happen before a proper logger is configured [Debug] Add BufferingLogger to buffer errors that happen before a proper logger is configured Aug 12, 2015
@nicolas-grekas nicolas-grekas changed the title [Debug] Add BufferingLogger to buffer errors that happen before a proper logger is configured [Debug] Add BufferingLogger for errors that happen before a proper logger is configured Aug 12, 2015
use Psr\Log\LoggerInterface;

/**
* A bootstrapping logger that can stack logs and flush them when required to an other logger.
Copy link
Member

Choose a reason for hiding this comment

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

to an other logger -> to another logger ?

@nicolas-grekas nicolas-grekas force-pushed the debug-boot branch 2 times, most recently from 4536f85 to c2e5ba8 Compare August 12, 2015 15:12
{
public function testFlush()
{
for ($strip = 0; $strip < 2; ++$strip) {
Copy link
Member

Choose a reason for hiding this comment

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

use a dataProvider for that instead of a loop in the test. It will be much easier to debug failures as we will know which case is failing.

Copy link
Member Author

Choose a reason for hiding this comment

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

dataProvider added

@nicolas-grekas nicolas-grekas force-pushed the debug-boot branch 3 times, most recently from e944b5e to 28d05be Compare August 13, 2015 06:08
@nicolas-grekas
Copy link
Member Author

Since deprecations are silenced and the default config is not to "scream" them, this will not save them for later logging for now. I need to figure out something about this.

Status: needs work

@nicolas-grekas
Copy link
Member Author

Fixed: deprecation notices are now screamed when $displayErrors is set to true

Status: needs review

@nicolas-grekas
Copy link
Member Author

Last iteration: I removed the code that stripped scope vars and trace args. We have no use case for it: deprecations are already cleanup from those, and we throw all the other error levels.

@nicolas-grekas nicolas-grekas force-pushed the debug-boot branch 5 times, most recently from 4b282c9 to 6026cf2 Compare August 17, 2015 08:39
@nicolas-grekas
Copy link
Member Author

PR refactored, really the last round this time (although I can't ensure that @stof won't have any comments ;)):
I replaced "configuration by interface" by proper constructor DI. This also fixes an ordering issue: having one bootstrapping logger per error level resulted in grouping of errors by level. Having only one now allows preserving the order of log lines.

@@ -152,6 +153,14 @@ public static function register($handler = null, $replace = true)
return $handler;
}

public function __construct(BufferingLogger $bootstrappingLogger = null)
{
if ($bootstrappingLogger) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be renamed?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think so: it's a BufferingLogger that is used for the bootstrapping step, thus a bootstrappingLogger internally.

@nicolas-grekas
Copy link
Member Author

@symfony/deciders should we merge this PR in 2.7? Even if this can be considered as a new feature, it fixes collecting early deprecation notices, that are currently completely silent on 2.7, and would stay so if we merge this one on 2.8. What do you think?

@fabpot
Copy link
Member

fabpot commented Sep 10, 2015

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 2a9647d into symfony:2.8 Sep 10, 2015
fabpot added a commit that referenced this pull request Sep 10, 2015
…ore a proper logger is configured (nicolas-grekas)

This PR was merged into the 2.8 branch.

Discussion
----------

[Debug] Add BufferingLogger for errors that happen before a proper logger is configured

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

This allows catching e.g. deprecations that happen during bootstrapping.

Commits
-------

2a9647d [Debug] Add BufferingLogger for errors that happen before a proper logger is configured
@nicolas-grekas nicolas-grekas deleted the debug-boot branch September 10, 2015 07:44
@xabbuh
Copy link
Member

xabbuh commented Oct 8, 2015

What about backporting this to 2.7 as @nicolas-grekas suggested?

@stof
Copy link
Member

stof commented Oct 8, 2015

Well, it is technically a new feature, so it belongs to 2.8.

and if people don't see some early deprecation warnings in 2.8, it is not a big issue: things still work. They will simply see it after upgrading to 2.8 (alongside new ones)

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.

8 participants