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

Global request logging WIP #18

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Global request logging WIP #18

wants to merge 1 commit into from

Conversation

kyranb
Copy link

@kyranb kyranb commented Apr 20, 2022

Hey Bilfeldt,

After your work on Footprints, I wanted to try and return the favour.

Description

This PR is a WIP. Haven't had the chance to test properly yet.

Does this close any currently open issues?

Aimes to fix #2

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update
    ...

Checklist

  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link
Owner

@bilfeldt bilfeldt left a comment

Choose a reason for hiding this comment

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

@kyranb I really appreciate this PR. Thanks a bunch.

Besides the comment in the review then I am not really sure I understand why you need two listeners? Is the $requestSendingEvent->request the actual instance that is being sent, because if so then adding the middleware to that one should be just fine I quess?

*/
public function handle(ResponseReceived $event)
{
$event->response->withMiddleware((new LoggingMiddleware(
Copy link
Owner

Choose a reason for hiding this comment

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

Question: Can we just use app(LoggingMiddleware::class) instead?

Copy link
Author

Choose a reason for hiding this comment

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

True, I can't see why note. That would make sense to resolve it rather than instantiating it again ☺️

*/
public function handle(RequestSending $event)
{
return $event->request->withMiddleware((new LoggingMiddleware(
Copy link
Owner

Choose a reason for hiding this comment

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

Question: Can we just use app(LoggingMiddleware::class) instead?

ResponseReceived::class => [
LogResponseReceived::class,
],
];
Copy link
Owner

Choose a reason for hiding this comment

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

Can we test this using a simple unit test that uses assertListening? 🤔

Event::assertListening(
    RequestSending::class,
    LogRequestSending::class
);

Event::assertListening(
    ResponseReceived::class,
    LogRequestSending::class
);

See:

@bilfeldt
Copy link
Owner

bilfeldt commented May 5, 2022

@kyranb Did you see me previous comment by any chance? 👍

@kyranb
Copy link
Author

kyranb commented May 6, 2022

@bilfeldt Sorry, yes I did but I haven't had a chance to dive back into this yet. I think you're correct, we only need to log the the sent request 👍

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

Successfully merging this pull request may close these issues.

Add global logging
2 participants