{"action":"created","comment":{"url":"https://api.github.com/repos/php-http/plugins/pulls/comments/44760905","id":44760905,"diff_hunk":"@@ -0,0 +1,74 @@\n+<?php\n+\n+namespace Http\\Client\\Plugin;\n+\n+use Http\\Client\\Exception;\n+use Http\\Client\\Plugin\\Normalizer\\Normalizer;\n+use Psr\\Http\\Message\\RequestInterface;\n+use Psr\\Http\\Message\\ResponseInterface;\n+use Psr\\Log\\LoggerInterface;\n+\n+/**\n+ * Log request, response and exception for a HTTP Client\n+ *\n+ * @author Joel Wurtz <joel.wurtz@gmail.com>\n+ */\n+class LoggerPlugin implements Plugin\n+{\n+    /**\n+     * @var LoggerInterface Logger to log request / response / exception for a http call\n+     */\n+    private $logger;\n+\n+    /**\n+     * @var Normalizer Normalize request and response to string or array\n+     */\n+    private $normalizer;\n+\n+    public function __construct(LoggerInterface $logger, Normalizer $normalizer)\n+    {\n+        $this->logger     = $logger;\n+        $this->normalizer = $normalizer;\n+    }\n+\n+    /**\n+     * {@inheritdoc}\n+     */\n+    public function handleRequest(RequestInterface $request, callable $next, callable $first)\n+    {\n+        $this->logger->info(sprintf('Emit request: \"%s\"', $this->normalizer->normalizeRequestToString($request)), ['request' => $this->normalizer->normalizeRequestToArray($request)]);\n+\n+        return $next($request)->then(function (ResponseInterface $response) use($request) {\n+            $this->logger->info(\n+                sprintf('Receive response: \"%s\" for request: \"%s\"', $this->normalizer->normalizeResponseToString($response), $this->normalizer->normalizeRequestToString($request)),\n+                [\n+                    'request' => $this->normalizer->normalizeRequestToArray($request),\n+                    'response' => $this->normalizer->normalizeResponseToArray($response),\n+                ]\n+            );\n+\n+            return $response;\n+        }, function (Exception $exception) use($request) {\n+            if ($exception instanceof Exception\\HttpException) {\n+                $this->logger->error(\n+                    sprintf('Error: \"%s\" with response: \"%s\" when emitting request: \"%s\"', $exception->getMessage(), $this->normalizer->normalizeResponseToString($exception->getResponse()), $this->normalizer->normalizeRequestToString($request)),\n+                    [\n+                        'request' => $this->normalizer->normalizeRequestToArray($request),\n+                        'response' => $this->normalizer->normalizeResponseToArray($exception->getResponse()),\n+                        'exception' => $exception\n+                    ]\n+                );\n+            } else {\n+                $this->logger->error(\n+                    sprintf('Error: \"%s\" when emitting request: \"%s\"', $exception->getMessage(), $this->normalizer->normalizeRequestToString($request)),\n+                    [\n+                        'request' => $this->normalizer->normalizeRequestToArray($request),\n+                        'exception' => $exception\n+                    ]\n+                );\n+            }\n+\n+            throw $exception;","path":"src/LoggerPlugin.php","position":71,"original_position":71,"commit_id":"82350afa387d05bb68f09bb65c88edfe43468ab0","original_commit_id":"82350afa387d05bb68f09bb65c88edfe43468ab0","user":{"login":"joelwurtz","id":90466,"avatar_url":"https://avatars.githubusercontent.com/u/90466?v=3","gravatar_id":"","url":"https://api.github.com/users/joelwurtz","html_url":"https://github.com/joelwurtz","followers_url":"https://api.github.com/users/joelwurtz/followers","following_url":"https://api.github.com/users/joelwurtz/following{/other_user}","gists_url":"https://api.github.com/users/joelwurtz/gists{/gist_id}","starred_url":"https://api.github.com/users/joelwurtz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joelwurtz/subscriptions","organizations_url":"https://api.github.com/users/joelwurtz/orgs","repos_url":"https://api.github.com/users/joelwurtz/repos","events_url":"https://api.github.com/users/joelwurtz/events{/privacy}","received_events_url":"https://api.github.com/users/joelwurtz/received_events","type":"User","site_admin":false},"body":"Yes when calling one of the callable passed to the then method, if it returns something then the value will go into the next onFulfilled callable, if it throw an exception it will go into the next onRejected callable.","created_at":"2015-11-13T08:50:47Z","updated_at":"2015-11-13T08:50:47Z","html_url":"https://github.com/php-http/plugins/pull/8#discussion_r44760905","pull_request_url":"https://api.github.com/repos/php-http/plugins/pulls/8","_links":{"self":{"href":"https://api.github.com/repos/php-http/plugins/pulls/comments/44760905"},"html":{"href":"https://github.com/php-http/plugins/pull/8#discussion_r44760905"},"pull_request":{"href":"https://api.github.com/repos/php-http/plugins/pulls/8"}}},"pull_request":{"url":"https://api.github.com/repos/php-http/plugins/pulls/8","id":50575789,"html_url":"https://github.com/php-http/plugins/pull/8","diff_url":"https://github.com/php-http/plugins/pull/8.diff","patch_url":"https://github.com/php-http/plugins/pull/8.patch","issue_url":"https://api.github.com/repos/php-http/plugins/issues/8","number":8,"state":"open","locked":false,"title":"Add logger plugin","user":{"login":"joelwurtz","id":90466,"avatar_url":"https://avatars.githubusercontent.com/u/90466?v=3","gravatar_id":"","url":"https://api.github.com/users/joelwurtz","html_url":"https://github.com/joelwurtz","followers_url":"https://api.github.com/users/joelwurtz/followers","following_url":"https://api.github.com/users/joelwurtz/following{/other_user}","gists_url":"https://api.github.com/users/joelwurtz/gists{/gist_id}","starred_url":"https://api.github.com/users/joelwurtz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joelwurtz/subscriptions","organizations_url":"https://api.github.com/users/joelwurtz/orgs","repos_url":"https://api.github.com/users/joelwurtz/repos","events_url":"https://api.github.com/users/joelwurtz/events{/privacy}","received_events_url":"https://api.github.com/users/joelwurtz/received_events","type":"User","site_admin":false},"body":"Actually don't know if this \"normalizer\" should be in the plugins library, WDYT ?","created_at":"2015-11-12T22:11:56Z","updated_at":"2015-11-13T08:50:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8ea6b03390c1d4b0d89373aeb746cdb1ea2815eb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/php-http/plugins/pulls/8/commits","review_comments_url":"https://api.github.com/repos/php-http/plugins/pulls/8/comments","review_comment_url":"https://api.github.com/repos/php-http/plugins/pulls/comments{/number}","comments_url":"https://api.github.com/repos/php-http/plugins/issues/8/comments","statuses_url":"https://api.github.com/repos/php-http/plugins/statuses/82350afa387d05bb68f09bb65c88edfe43468ab0","head":{"label":"php-http:feature/logger-plugin","ref":"feature/logger-plugin","sha":"82350afa387d05bb68f09bb65c88edfe43468ab0","user":{"login":"php-http","id":12104859,"avatar_url":"https://avatars.githubusercontent.com/u/12104859?v=3","gravatar_id":"","url":"https://api.github.com/users/php-http","html_url":"https://github.com/php-http","followers_url":"https://api.github.com/users/php-http/followers","following_url":"https://api.github.com/users/php-http/following{/other_user}","gists_url":"https://api.github.com/users/php-http/gists{/gist_id}","starred_url":"https://api.github.com/users/php-http/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/php-http/subscriptions","organizations_url":"https://api.github.com/users/php-http/orgs","repos_url":"https://api.github.com/users/php-http/repos","events_url":"https://api.github.com/users/php-http/events{/privacy}","received_events_url":"https://api.github.com/users/php-http/received_events","type":"Organization","site_admin":false},"repo":{"id":45717095,"name":"plugins","full_name":"php-http/plugins","owner":{"login":"php-http","id":12104859,"avatar_url":"https://avatars.githubusercontent.com/u/12104859?v=3","gravatar_id":"","url":"https://api.github.com/users/php-http","html_url":"https://github.com/php-http","followers_url":"https://api.github.com/users/php-http/followers","following_url":"https://api.github.com/users/php-http/following{/other_user}","gists_url":"https://api.github.com/users/php-http/gists{/gist_id}","starred_url":"https://api.github.com/users/php-http/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/php-http/subscriptions","organizations_url":"https://api.github.com/users/php-http/orgs","repos_url":"https://api.github.com/users/php-http/repos","events_url":"https://api.github.com/users/php-http/events{/privacy}","received_events_url":"https://api.github.com/users/php-http/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/php-http/plugins","description":"Plugin client, decorate http client with middlewares","fork":false,"url":"https://api.github.com/repos/php-http/plugins","forks_url":"https://api.github.com/repos/php-http/plugins/forks","keys_url":"https://api.github.com/repos/php-http/plugins/keys{/key_id}","collaborators_url":"https://api.github.com/repos/php-http/plugins/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/php-http/plugins/teams","hooks_url":"https://api.github.com/repos/php-http/plugins/hooks","issue_events_url":"https://api.github.com/repos/php-http/plugins/issues/events{/number}","events_url":"https://api.github.com/repos/php-http/plugins/events","assignees_url":"https://api.github.com/repos/php-http/plugins/assignees{/user}","branches_url":"https://api.github.com/repos/php-http/plugins/branches{/branch}","tags_url":"https://api.github.com/repos/php-http/plugins/tags","blobs_url":"https://api.github.com/repos/php-http/plugins/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/php-http/plugins/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/php-http/plugins/git/refs{/sha}","trees_url":"https://api.github.com/repos/php-http/plugins/git/trees{/sha}","statuses_url":"https://api.github.com/repos/php-http/plugins/statuses/{sha}","languages_url":"https://api.github.com/repos/php-http/plugins/languages","stargazers_url":"https://api.github.com/repos/php-http/plugins/stargazers","contributors_url":"https://api.github.com/repos/php-http/plugins/contributors","subscribers_url":"https://api.github.com/repos/php-http/plugins/subscribers","subscription_url":"https://api.github.com/repos/php-http/plugins/subscription","commits_url":"https://api.github.com/repos/php-http/plugins/commits{/sha}","git_commits_url":"https://api.github.com/repos/php-http/plugins/git/commits{/sha}","comments_url":"https://api.github.com/repos/php-http/plugins/comments{/number}","issue_comment_url":"https://api.github.com/repos/php-http/plugins/issues/comments{/number}","contents_url":"https://api.github.com/repos/php-http/plugins/contents/{+path}","compare_url":"https://api.github.com/repos/php-http/plugins/compare/{base}...{head}","merges_url":"https://api.github.com/repos/php-http/plugins/merges","archive_url":"https://api.github.com/repos/php-http/plugins/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/php-http/plugins/downloads","issues_url":"https://api.github.com/repos/php-http/plugins/issues{/number}","pulls_url":"https://api.github.com/repos/php-http/plugins/pulls{/number}","milestones_url":"https://api.github.com/repos/php-http/plugins/milestones{/number}","notifications_url":"https://api.github.com/repos/php-http/plugins/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/php-http/plugins/labels{/name}","releases_url":"https://api.github.com/repos/php-http/plugins/releases{/id}","created_at":"2015-11-07T01:13:49Z","updated_at":"2015-11-08T10:00:07Z","pushed_at":"2015-11-13T00:53:19Z","git_url":"git://github.com/php-http/plugins.git","ssh_url":"git@github.com:php-http/plugins.git","clone_url":"https://github.com/php-http/plugins.git","svn_url":"https://github.com/php-http/plugins","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":0,"default_branch":"master"}},"base":{"label":"php-http:master","ref":"master","sha":"0f555a286010b05a9ce87a6df59a4348bb137cdb","user":{"login":"php-http","id":12104859,"avatar_url":"https://avatars.githubusercontent.com/u/12104859?v=3","gravatar_id":"","url":"https://api.github.com/users/php-http","html_url":"https://github.com/php-http","followers_url":"https://api.github.com/users/php-http/followers","following_url":"https://api.github.com/users/php-http/following{/other_user}","gists_url":"https://api.github.com/users/php-http/gists{/gist_id}","starred_url":"https://api.github.com/users/php-http/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/php-http/subscriptions","organizations_url":"https://api.github.com/users/php-http/orgs","repos_url":"https://api.github.com/users/php-http/repos","events_url":"https://api.github.com/users/php-http/events{/privacy}","received_events_url":"https://api.github.com/users/php-http/received_events","type":"Organization","site_admin":false},"repo":{"id":45717095,"name":"plugins","full_name":"php-http/plugins","owner":{"login":"php-http","id":12104859,"avatar_url":"https://avatars.githubusercontent.com/u/12104859?v=3","gravatar_id":"","url":"https://api.github.com/users/php-http","html_url":"https://github.com/php-http","followers_url":"https://api.github.com/users/php-http/followers","following_url":"https://api.github.com/users/php-http/following{/other_user}","gists_url":"https://api.github.com/users/php-http/gists{/gist_id}","starred_url":"https://api.github.com/users/php-http/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/php-http/subscriptions","organizations_url":"https://api.github.com/users/php-http/orgs","repos_url":"https://api.github.com/users/php-http/repos","events_url":"https://api.github.com/users/php-http/events{/privacy}","received_events_url":"https://api.github.com/users/php-http/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/php-http/plugins","description":"Plugin client, decorate http client with middlewares","fork":false,"url":"https://api.github.com/repos/php-http/plugins","forks_url":"https://api.github.com/repos/php-http/plugins/forks","keys_url":"https://api.github.com/repos/php-http/plugins/keys{/key_id}","collaborators_url":"https://api.github.com/repos/php-http/plugins/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/php-http/plugins/teams","hooks_url":"https://api.github.com/repos/php-http/plugins/hooks","issue_events_url":"https://api.github.com/repos/php-http/plugins/issues/events{/number}","events_url":"https://api.github.com/repos/php-http/plugins/events","assignees_url":"https://api.github.com/repos/php-http/plugins/assignees{/user}","branches_url":"https://api.github.com/repos/php-http/plugins/branches{/branch}","tags_url":"https://api.github.com/repos/php-http/plugins/tags","blobs_url":"https://api.github.com/repos/php-http/plugins/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/php-http/plugins/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/php-http/plugins/git/refs{/sha}","trees_url":"https://api.github.com/repos/php-http/plugins/git/trees{/sha}","statuses_url":"https://api.github.com/repos/php-http/plugins/statuses/{sha}","languages_url":"https://api.github.com/repos/php-http/plugins/languages","stargazers_url":"https://api.github.com/repos/php-http/plugins/stargazers","contributors_url":"https://api.github.com/repos/php-http/plugins/contributors","subscribers_url":"https://api.github.com/repos/php-http/plugins/subscribers","subscription_url":"https://api.github.com/repos/php-http/plugins/subscription","commits_url":"https://api.github.com/repos/php-http/plugins/commits{/sha}","git_commits_url":"https://api.github.com/repos/php-http/plugins/git/commits{/sha}","comments_url":"https://api.github.com/repos/php-http/plugins/comments{/number}","issue_comment_url":"https://api.github.com/repos/php-http/plugins/issues/comments{/number}","contents_url":"https://api.github.com/repos/php-http/plugins/contents/{+path}","compare_url":"https://api.github.com/repos/php-http/plugins/compare/{base}...{head}","merges_url":"https://api.github.com/repos/php-http/plugins/merges","archive_url":"https://api.github.com/repos/php-http/plugins/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/php-http/plugins/downloads","issues_url":"https://api.github.com/repos/php-http/plugins/issues{/number}","pulls_url":"https://api.github.com/repos/php-http/plugins/pulls{/number}","milestones_url":"https://api.github.com/repos/php-http/plugins/milestones{/number}","notifications_url":"https://api.github.com/repos/php-http/plugins/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/php-http/plugins/labels{/name}","releases_url":"https://api.github.com/repos/php-http/plugins/releases{/id}","created_at":"2015-11-07T01:13:49Z","updated_at":"2015-11-08T10:00:07Z","pushed_at":"2015-11-13T00:53:19Z","git_url":"git://github.com/php-http/plugins.git","ssh_url":"git@github.com:php-http/plugins.git","clone_url":"https://github.com/php-http/plugins.git","svn_url":"https://github.com/php-http/plugins","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/php-http/plugins/pulls/8"},"html":{"href":"https://github.com/php-http/plugins/pull/8"},"issue":{"href":"https://api.github.com/repos/php-http/plugins/issues/8"},"comments":{"href":"https://api.github.com/repos/php-http/plugins/issues/8/comments"},"review_comments":{"href":"https://api.github.com/repos/php-http/plugins/pulls/8/comments"},"review_comment":{"href":"https://api.github.com/repos/php-http/plugins/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/php-http/plugins/pulls/8/commits"},"statuses":{"href":"https://api.github.com/repos/php-http/plugins/statuses/82350afa387d05bb68f09bb65c88edfe43468ab0"}}}}