{"id":15952182,"url":"https://github.com/liborm85/loggable-http-client","last_synced_at":"2025-03-17T15:31:19.263Z","repository":{"id":158774084,"uuid":"625531956","full_name":"liborm85/loggable-http-client","owner":"liborm85","description":"Extended logging for the Symfony HTTP Client allowing especially to log the content of the request and response.","archived":false,"fork":false,"pushed_at":"2024-10-04T12:59:55.000Z","size":54,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-08T13:07:02.944Z","etag":null,"topics":["http","http-client","log","logger","logging","php","psr-3","symfony"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/liborm85.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-04-09T12:06:49.000Z","updated_at":"2024-10-04T12:55:40.000Z","dependencies_parsed_at":"2024-01-30T18:00:23.557Z","dependency_job_id":null,"html_url":"https://github.com/liborm85/loggable-http-client","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liborm85%2Floggable-http-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liborm85%2Floggable-http-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liborm85%2Floggable-http-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liborm85%2Floggable-http-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/liborm85","download_url":"https://codeload.github.com/liborm85/loggable-http-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221695526,"owners_count":16865235,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http","http-client","log","logger","logging","php","psr-3","symfony"],"created_at":"2024-10-07T13:07:09.663Z","updated_at":"2024-10-27T15:11:03.726Z","avatar_url":"https://github.com/liborm85.png","language":"PHP","readme":"# Loggable HTTP Client [![Packagist](https://img.shields.io/packagist/v/liborm85/loggable-http-client.svg)](https://packagist.org/packages/liborm85/loggable-http-client)\n\nExtended logging for the Symfony HTTP Client allowing especially to log the content of the request and response.\n\nAdds events to [PSR-3](https://www.php-fig.org/psr/psr-3/) logger interface:\n- `'Response content:'` (level: `info`) - response body content received; in context is available (details in [Usage](#usage)):\n  - `request` (`\\Liborm85\\LoggableHttpClient\\Context\\RequestContextInterface`)\n  - `response` (`\\Liborm85\\LoggableHttpClient\\Context\\ResponseContextInterface`)\n  - `info` (`\\Liborm85\\LoggableHttpClient\\Context\\InfoContextInterface`)\n- `'Response content (canceled):'` (level: `info`) - same as above, only for canceled request (not all data may be available)\n\nAdds additional information to `getInfo()` method:\n- `request_json` (`mixed`) - `json` option from request `$options` (if is provided)\n- `request_body` (`\\Liborm85\\LoggableHttpClient\\Body\\BodyInterface`) - `body` option from request `$options` transformed to object (if is provided)\n- `response_time` (`float`) - the time when the response was received\n\n\u003c!-- TBD\n## Installation\n\nYou can install it with:\n```\ncomposer require liborm85/loggable-http-client\n```\n--\u003e\n\n## Usage\n\n```php\n\u003c?php\n\n$httpClient = \\Symfony\\Component\\HttpClient\\HttpClient::create(); // optional\n$loggableHttpClient = new \\Liborm85\\LoggableHttpClient\\LoggableHttpClient($httpClient);\n$loggableHttpClient-\u003esetLogger(new \\MyLogger());\n\n$response = $loggableHttpClient-\u003erequest('GET', 'https://example.com');\n\n\nclass MyLogger extends \\Psr\\Log\\AbstractLogger\n{\n\n    public function log($level, $message, array $context = []): void\n    {\n        if (isset($context['request']) \u0026\u0026 ($context['request'] instanceof \\Liborm85\\LoggableHttpClient\\Context\\RequestContextInterface)) {\n            $context['request']-\u003egetContent(); // request content body as string\n            (string)$context['request']; // is Stringable, request content body as string\n            $context['request']-\u003etoStream(); // request content body as PHP stream\n            $context['request']-\u003egetHeadersAsString(); // request headers as string\n            $context['request']-\u003egetHeaders(); // request headers as array (string[][])\n            $context['request']-\u003egetRequestTime(); // request time as DateTimeInterface\n            $context['request']-\u003egetRequestMethod(); // request HTTP method\n            $context['request']-\u003egetUrl(); // full request URL\n        }\n\n        if (isset($context['response']) \u0026\u0026 ($context['response'] instanceof \\Liborm85\\LoggableHttpClient\\Context\\ResponseContextInterface)) {\n            $context['response']-\u003egetContent(); // response content body as string\n            (string)$context['response']; // is Stringable, response content body as string\n            $context['response']-\u003etoStream(); // response content body as PHP stream\n            $context['response']-\u003egetHeadersAsString(); // response headers as string\n            $context['response']-\u003egetHeaders(); // response headers as array (string[][])\n            $context['response']-\u003egetResponseTime(); // response time as DateTimeInterface\n        }\n\n        if (isset($context['info']) \u0026\u0026 ($context['info'] instanceof \\Liborm85\\LoggableHttpClient\\Context\\InfoContextInterface)) {\n            $context['info']-\u003egetInfo(); // return all available information\n            $context['info']-\u003egetInfo('url'); // return one information for provided type\n        }\n    }\n\n}\n```\n\n## License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliborm85%2Floggable-http-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliborm85%2Floggable-http-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliborm85%2Floggable-http-client/lists"}