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

[HttpClient] Control logging #50168

Closed
ro0NL opened this issue Apr 27, 2023 · 2 comments
Closed

[HttpClient] Control logging #50168

ro0NL opened this issue Apr 27, 2023 · 2 comments

Comments

@ro0NL
Copy link
Contributor

ro0NL commented Apr 27, 2023

Description

Hi,

Using HttpClient i found no way to;

  • log (masked) request bodies/headers for eg. urls matching X
  • log (masked) response bodies/headers eg. based on status code X and/or corresponding request
  • determine a log level based on response/request
  • determine the log channel (but i guess this is matter of manually calling CurlHttpClient::setLogger, but AFAIK it can't be wired using framework configuration)

Is there a way to achieve this currently?

At the moment we rely on https://github.com/php-http/logger-plugin, but i'd like to do it with Symfony HTTP Client, rather than having one HTTP client decorate another.

It should be noted this decoration approach (httplug => sfclient) creates double logs, somewhat by default. Luckily we only persist the specific channel in the outer client, not the http_client channel. However during console logs (-vv) things are super weird :)

Example

No response

@ro0NL
Copy link
Contributor Author

ro0NL commented Apr 27, 2023

setLogger feels a bit odd, im wondering if it should be options instead. So in YAML we could do something like:

# config/packages/framework.yaml
framework:
    http_client:
        scoped_clients:
            example_api:
                base_uri: 'https://example.com/'
                logger: '@monolog.logger.example_api'
                log_formatter: '@my_special_formatter' # API TBD

@ro0NL
Copy link
Contributor Author

ro0NL commented May 1, 2023

this is the alternative in PHP:

$httpClient = new PluginClient(new Psr18Client($httpClient), [
    new LoggerPlugin($this->logger, new SomeMessageFormatter()),
]);

WFM

@ro0NL ro0NL closed this as completed May 1, 2023
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

3 participants