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

[Profiler] could not access logs in tests #33384

Closed
massimilianobraglia opened this issue Aug 29, 2019 · 5 comments
Closed

[Profiler] could not access logs in tests #33384

massimilianobraglia opened this issue Aug 29, 2019 · 5 comments

Comments

@massimilianobraglia
Copy link
Contributor

Symfony version(s) affected: 4.3.4 (upgrading from 4.2.5)

Description
#30339
This PR disabled the debug logger in cli. During the execution of my functional tests with PHPUnit I cannot access the logs contained in the profiler's logger collector

        $collector = $profile->getCollector('logger');
        $logs = $collector->getLogs()->getValue(true);

these lines gathered also the logs made by a GuzzleHttp client instance (I can dump the log messages).

I need to check those logs in order to be sure that the GuzzleClient makes the right requests needed by my application.

How can I access those logs? Is there another way to do that?

Thank you in advance! 😄

@ogizanagi
Copy link
Member

ogizanagi commented Sep 12, 2019

I think the best way for you to access the logs in functional tests is not using the profiler, but to add the Monolog test handler in your test env:

# config/packages/test/monolog.yaml

monolog:
    handlers:
         [...]

        # Test handler allows to perform assertions on logs:
        test:
            type: test
            level: debug
            process_psr_3_messages: false
            channels: ["!event", "!doctrine"]

Declaring an alias to the service:

# config/packages/test/monolog.yaml

services:
    Monolog\Handler\TestHandler:
        public: true # to be accessible from tests
        alias: monolog.handler.test

you could easily access it in tests from the client container, and use its assertions methods.

@massimilianobraglia
Copy link
Contributor Author

hey there @ogizanagi! Thank you for your answer! I'll try this approach as soon as possible and I'll let you know :)

@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@carsonbot
Copy link

Hello? This issue is about to be closed if nobody replies.

@carsonbot
Copy link

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

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

No branches or pull requests

4 participants