-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[MonologBridge] Fix interactive_only not preventing propagation
#64207
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
base: 7.4
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,7 +99,23 @@ public function handle(LogRecord $record): bool | |
| { | ||
| // we have to update the logging level each time because the verbosity of the | ||
| // console output might have changed in the meantime (it is not immutable) | ||
| return $this->updateLevel() && parent::handle($record); | ||
| if (!$this->updateLevel()) { | ||
| return false; | ||
| } | ||
|
|
||
| // AbstractProcessingHandler::handle() reads the $bubble property directly | ||
| // instead of calling getBubble(), so the dynamic value computed by the | ||
| // override above never reaches Monolog's Logger propagation loop. Mirror | ||
| // it into the property for the duration of this call so that | ||
| // interactive_only actually prevents propagation as documented. | ||
| $previousBubble = $this->bubble; | ||
| $this->bubble = $this->getBubble(); | ||
|
|
||
| try { | ||
| return parent::handle($record); | ||
| } finally { | ||
| $this->bubble = $previousBubble; | ||
| } | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Happy to update the fix to be an alternative "more correct" fix if there's a better way, but this solution gets the test passing.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like something that should be fixed on Monolog's side instead.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix submitted here: Seldaek/monolog#2031
philbates35 marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| public function setInput(InputInterface $input): void | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
|
|
||
| namespace Symfony\Bridge\Monolog\Tests\Handler; | ||
|
|
||
| use Monolog\Handler\TestHandler; | ||
| use Monolog\Level; | ||
| use Monolog\Logger; | ||
| use PHPUnit\Framework\Attributes\DataProvider; | ||
|
|
@@ -262,6 +263,46 @@ public function testInteractiveOnly() | |
| self::assertTrue($handler->getBubble(), '->getBubble returns true when input is not interactive and interactiveOnly is true'); | ||
| } | ||
|
|
||
| public function testInteractiveOnlyPreventsPropagationWhenInteractive() | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fails without the fix, proving that propogation isn't stopped, which contradicts the docs and I believe the intended behaviour. |
||
| { | ||
| $interactiveInput = $this->createStub(InputInterface::class); | ||
| $interactiveInput->method('isInteractive')->willReturn(true); | ||
|
|
||
| $consoleHandler = new ConsoleHandler(interactiveOnly: true); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't use named arguments in test, because they are not supported by our BC policy.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed π |
||
| $consoleHandler->setInput($interactiveInput); | ||
| $consoleHandler->setOutput(new BufferedOutput(OutputInterface::VERBOSITY_VERBOSE)); | ||
|
|
||
| $sibling = new TestHandler(); | ||
| $logger = new Logger('test', [$consoleHandler, $sibling]); | ||
|
|
||
| $logger->warning('hello'); | ||
|
|
||
| self::assertFalse( | ||
| $sibling->hasWarningRecords(), | ||
| 'sibling handler must not receive records when interactive_only is true and input is interactive', | ||
| ); | ||
| } | ||
|
|
||
| public function testInteractiveOnlyAllowsPropagationWhenNotInteractive() | ||
| { | ||
| $nonInteractiveInput = $this->createStub(InputInterface::class); | ||
| $nonInteractiveInput->method('isInteractive')->willReturn(false); | ||
|
|
||
| $consoleHandler = new ConsoleHandler(interactiveOnly: true); | ||
| $consoleHandler->setInput($nonInteractiveInput); | ||
| $consoleHandler->setOutput(new BufferedOutput(OutputInterface::VERBOSITY_VERBOSE)); | ||
|
|
||
| $sibling = new TestHandler(); | ||
| $logger = new Logger('test', [$consoleHandler, $sibling]); | ||
|
|
||
| $logger->warning('hello'); | ||
|
|
||
| self::assertTrue( | ||
| $sibling->hasWarningRecords(), | ||
| 'sibling handler must still receive records when interactive_only is true but input is not interactive', | ||
| ); | ||
| } | ||
|
|
||
| public function testNestedCommandsDoNotCloseHandler() | ||
| { | ||
| $output = new BufferedOutput(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this outdated comment.