{"action":"created","comment":{"url":"https://api.github.com/repos/symfony/symfony/pulls/comments/74212777","id":74212777,"diff_hunk":"@@ -0,0 +1,83 @@\n+<?php\n+\n+namespace Symfony\\Component\\Console\\EventListener;\n+\n+use Psr\\Log\\LoggerInterface;\n+use Symfony\\Component\\Console\\ConsoleEvents;\n+use Symfony\\Component\\Console\\Event\\ConsoleExceptionEvent;\n+use Symfony\\Component\\Console\\Event\\ConsoleTerminateEvent;\n+use Symfony\\Component\\EventDispatcher\\EventSubscriberInterface;\n+\n+/**\n+ * Console exception listener.\n+ *\n+ * Attempts to log exceptions or abnormal terminations of console commands.\n+ *\n+ * @author James Halsall <james.t.halsall@googlemail.com>\n+ */\n+class ExceptionListener implements EventSubscriberInterface\n+{\n+    protected $logger;\n+\n+    /**\n+     * Constructor.\n+     *\n+     * @param LoggerInterface $logger A logger\n+     */\n+    public function __construct(LoggerInterface $logger = null)\n+    {\n+        $this->logger = $logger;\n+    }\n+\n+    /**\n+     * Handles console command exception.\n+     *\n+     * @param ConsoleExceptionEvent $event Console event\n+     */\n+    public function onKernelException(ConsoleExceptionEvent $event)\n+    {\n+        if (null === $this->logger) {\n+            return;\n+        }\n+\n+        $exception = $event->getException();\n+\n+        $this->logger->error($exception->getMessage(), array('exception' => $exception));\n+    }\n+\n+    /**\n+     * Handles termination of console command.\n+     *\n+     * @param ConsoleTerminateEvent $event Console event\n+     */\n+    public function onKernelTerminate(ConsoleTerminateEvent $event)\n+    {\n+        if (null === $this->logger) {\n+            return;\n+        }\n+\n+        $exitCode = $event->getExitCode();\n+\n+        if ($exitCode === 0) {\n+            return;\n+        }\n+\n+        $message = sprintf(\n+            'Command `%s` exited with status code %d',\n+            implode(' ', $_SERVER['argv']),","path":"src/Symfony/Component/Console/EventListener/ExceptionListener.php","position":67,"original_position":67,"commit_id":"36a1dd6427b57b32da0d3cd4674e9d790775cc3d","original_commit_id":"36a1dd6427b57b32da0d3cd4674e9d790775cc3d","user":{"login":"lyrixx","id":408368,"avatar_url":"https://avatars.githubusercontent.com/u/408368?v=3","gravatar_id":"","url":"https://api.github.com/users/lyrixx","html_url":"https://github.com/lyrixx","followers_url":"https://api.github.com/users/lyrixx/followers","following_url":"https://api.github.com/users/lyrixx/following{/other_user}","gists_url":"https://api.github.com/users/lyrixx/gists{/gist_id}","starred_url":"https://api.github.com/users/lyrixx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lyrixx/subscriptions","organizations_url":"https://api.github.com/users/lyrixx/orgs","repos_url":"https://api.github.com/users/lyrixx/repos","events_url":"https://api.github.com/users/lyrixx/events{/privacy}","received_events_url":"https://api.github.com/users/lyrixx/received_events","type":"User","site_admin":false},"body":"For information, we are using $_SERVER also:\r\n```\r\n<?php\r\n\r\nnamespace SensioLabs\\Toolkit\\EventListener\\Command;\r\n\r\nuse Psr\\Log\\LoggerInterface;\r\nuse Psr\\Log\\NullLogger;\r\nuse Symfony\\Component\\Console\\ConsoleEvents;\r\nuse Symfony\\Component\\Console\\Event\\ConsoleExceptionEvent;\r\nuse Symfony\\Component\\Console\\Event\\ConsoleTerminateEvent;\r\nuse Symfony\\Component\\EventDispatcher\\EventSubscriberInterface;\r\n\r\nclass LogCommandListener implements EventSubscriberInterface\r\n{\r\n    private $logger;\r\n\r\n    public function __construct(LoggerInterface $logger = null)\r\n    {\r\n        $this->logger = $logger ?: new NullLogger();\r\n    }\r\n\r\n    public static function getSubscribedEvents()\r\n    {\r\n        return array(\r\n            ConsoleEvents::EXCEPTION => 'onConsoleException',\r\n            ConsoleEvents::TERMINATE => 'onConsoleTerminate',\r\n        );\r\n    }\r\n\r\n    public function onConsoleException(ConsoleExceptionEvent $event)\r\n    {\r\n        $this->logger->error(sprintf('Exception thrown while running command: \"%s\". Message: \"%s\".', implode(' ', $_SERVER['argv']), $event->getException()->getMessage()), ['exception' => $event->getException()]);\r\n    }\r\n\r\n    public function onConsoleTerminate(ConsoleTerminateEvent $event)\r\n    {\r\n        $exitCode = $event->getExitCode();\r\n        if (0 !== $exitCode) {\r\n            $this->logger->error(sprintf('Command \"%s\" exited with code %d.', implode(' ', $_SERVER['argv']), $exitCode));\r\n        }\r\n    }\r\n}\r\n```","created_at":"2016-08-10T09:27:28Z","updated_at":"2016-08-10T09:27:28Z","html_url":"https://github.com/symfony/symfony/pull/19382#discussion_r74212777","pull_request_url":"https://api.github.com/repos/symfony/symfony/pulls/19382","_links":{"self":{"href":"https://api.github.com/repos/symfony/symfony/pulls/comments/74212777"},"html":{"href":"https://github.com/symfony/symfony/pull/19382#discussion_r74212777"},"pull_request":{"href":"https://api.github.com/repos/symfony/symfony/pulls/19382"}}},"pull_request":{"url":"https://api.github.com/repos/symfony/symfony/pulls/19382","id":77853467,"html_url":"https://github.com/symfony/symfony/pull/19382","diff_url":"https://github.com/symfony/symfony/pull/19382.diff","patch_url":"https://github.com/symfony/symfony/pull/19382.patch","issue_url":"https://api.github.com/repos/symfony/symfony/issues/19382","number":19382,"state":"open","locked":false,"title":"[WIP] [Console] Add basic support for automatic console exception logging","user":{"login":"jameshalsall","id":499932,"avatar_url":"https://avatars.githubusercontent.com/u/499932?v=3","gravatar_id":"","url":"https://api.github.com/users/jameshalsall","html_url":"https://github.com/jameshalsall","followers_url":"https://api.github.com/users/jameshalsall/followers","following_url":"https://api.github.com/users/jameshalsall/following{/other_user}","gists_url":"https://api.github.com/users/jameshalsall/gists{/gist_id}","starred_url":"https://api.github.com/users/jameshalsall/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jameshalsall/subscriptions","organizations_url":"https://api.github.com/users/jameshalsall/orgs","repos_url":"https://api.github.com/users/jameshalsall/repos","events_url":"https://api.github.com/users/jameshalsall/events{/privacy}","received_events_url":"https://api.github.com/users/jameshalsall/received_events","type":"User","site_admin":false},"body":"| Q             | A\r\n| ------------- | ---\r\n| Branch?       | master\r\n| Bug fix?      | no\r\n| New feature?  | yes\r\n| BC breaks?    | no\r\n| Deprecations? | no\r\n| Tests pass?   | yes (still to write tests for new feature)\r\n| Fixed tickets | #10895\r\n| License       | MIT\r\n| Doc PR        | (TO DO)\r\n\r\n\r\nThis is a quick initial concept for automatic exception logging, it currently takes the 2 listeners outlined in the docs (http://symfony.com/doc/current/cookbook/console/logging.html) and brings them into the standard edition.\r\n\r\nI'd like to get some feedback before writing tests and updating the docs in a separate PR.\r\n\r\nTODO:\r\n\r\n- [ ] Confirm messaging + translations(?)\r\n- [ ] Write tests\r\n- [ ] Update docs in separate PR\r\n- [ ] Prevent console errors from writing to stderr","created_at":"2016-07-18T18:17:56Z","updated_at":"2016-08-10T09:27:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3444c30ab7c271c198e16758c311d54a08e7e38f","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/symfony/symfony/pulls/19382/commits","review_comments_url":"https://api.github.com/repos/symfony/symfony/pulls/19382/comments","review_comment_url":"https://api.github.com/repos/symfony/symfony/pulls/comments{/number}","comments_url":"https://api.github.com/repos/symfony/symfony/issues/19382/comments","statuses_url":"https://api.github.com/repos/symfony/symfony/statuses/36a1dd6427b57b32da0d3cd4674e9d790775cc3d","head":{"label":"jameshalsall:automatic-console-exception-logging","ref":"automatic-console-exception-logging","sha":"36a1dd6427b57b32da0d3cd4674e9d790775cc3d","user":{"login":"jameshalsall","id":499932,"avatar_url":"https://avatars.githubusercontent.com/u/499932?v=3","gravatar_id":"","url":"https://api.github.com/users/jameshalsall","html_url":"https://github.com/jameshalsall","followers_url":"https://api.github.com/users/jameshalsall/followers","following_url":"https://api.github.com/users/jameshalsall/following{/other_user}","gists_url":"https://api.github.com/users/jameshalsall/gists{/gist_id}","starred_url":"https://api.github.com/users/jameshalsall/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jameshalsall/subscriptions","organizations_url":"https://api.github.com/users/jameshalsall/orgs","repos_url":"https://api.github.com/users/jameshalsall/repos","events_url":"https://api.github.com/users/jameshalsall/events{/privacy}","received_events_url":"https://api.github.com/users/jameshalsall/received_events","type":"User","site_admin":false},"repo":{"id":16462879,"name":"symfony","full_name":"jameshalsall/symfony","owner":{"login":"jameshalsall","id":499932,"avatar_url":"https://avatars.githubusercontent.com/u/499932?v=3","gravatar_id":"","url":"https://api.github.com/users/jameshalsall","html_url":"https://github.com/jameshalsall","followers_url":"https://api.github.com/users/jameshalsall/followers","following_url":"https://api.github.com/users/jameshalsall/following{/other_user}","gists_url":"https://api.github.com/users/jameshalsall/gists{/gist_id}","starred_url":"https://api.github.com/users/jameshalsall/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jameshalsall/subscriptions","organizations_url":"https://api.github.com/users/jameshalsall/orgs","repos_url":"https://api.github.com/users/jameshalsall/repos","events_url":"https://api.github.com/users/jameshalsall/events{/privacy}","received_events_url":"https://api.github.com/users/jameshalsall/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jameshalsall/symfony","description":"The Symfony PHP framework","fork":true,"url":"https://api.github.com/repos/jameshalsall/symfony","forks_url":"https://api.github.com/repos/jameshalsall/symfony/forks","keys_url":"https://api.github.com/repos/jameshalsall/symfony/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jameshalsall/symfony/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jameshalsall/symfony/teams","hooks_url":"https://api.github.com/repos/jameshalsall/symfony/hooks","issue_events_url":"https://api.github.com/repos/jameshalsall/symfony/issues/events{/number}","events_url":"https://api.github.com/repos/jameshalsall/symfony/events","assignees_url":"https://api.github.com/repos/jameshalsall/symfony/assignees{/user}","branches_url":"https://api.github.com/repos/jameshalsall/symfony/branches{/branch}","tags_url":"https://api.github.com/repos/jameshalsall/symfony/tags","blobs_url":"https://api.github.com/repos/jameshalsall/symfony/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jameshalsall/symfony/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jameshalsall/symfony/git/refs{/sha}","trees_url":"https://api.github.com/repos/jameshalsall/symfony/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jameshalsall/symfony/statuses/{sha}","languages_url":"https://api.github.com/repos/jameshalsall/symfony/languages","stargazers_url":"https://api.github.com/repos/jameshalsall/symfony/stargazers","contributors_url":"https://api.github.com/repos/jameshalsall/symfony/contributors","subscribers_url":"https://api.github.com/repos/jameshalsall/symfony/subscribers","subscription_url":"https://api.github.com/repos/jameshalsall/symfony/subscription","commits_url":"https://api.github.com/repos/jameshalsall/symfony/commits{/sha}","git_commits_url":"https://api.github.com/repos/jameshalsall/symfony/git/commits{/sha}","comments_url":"https://api.github.com/repos/jameshalsall/symfony/comments{/number}","issue_comment_url":"https://api.github.com/repos/jameshalsall/symfony/issues/comments{/number}","contents_url":"https://api.github.com/repos/jameshalsall/symfony/contents/{+path}","compare_url":"https://api.github.com/repos/jameshalsall/symfony/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jameshalsall/symfony/merges","archive_url":"https://api.github.com/repos/jameshalsall/symfony/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jameshalsall/symfony/downloads","issues_url":"https://api.github.com/repos/jameshalsall/symfony/issues{/number}","pulls_url":"https://api.github.com/repos/jameshalsall/symfony/pulls{/number}","milestones_url":"https://api.github.com/repos/jameshalsall/symfony/milestones{/number}","notifications_url":"https://api.github.com/repos/jameshalsall/symfony/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jameshalsall/symfony/labels{/name}","releases_url":"https://api.github.com/repos/jameshalsall/symfony/releases{/id}","deployments_url":"https://api.github.com/repos/jameshalsall/symfony/deployments","created_at":"2014-02-02T20:49:02Z","updated_at":"2016-07-18T17:46:11Z","pushed_at":"2016-08-09T18:58:24Z","git_url":"git://github.com/jameshalsall/symfony.git","ssh_url":"git@github.com:jameshalsall/symfony.git","clone_url":"https://github.com/jameshalsall/symfony.git","svn_url":"https://github.com/jameshalsall/symfony","homepage":"symfony.com","size":68464,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"symfony:master","ref":"master","sha":"ccb684a8332425752c0fb67cdb2fecf66ff2da77","user":{"login":"symfony","id":143937,"avatar_url":"https://avatars.githubusercontent.com/u/143937?v=3","gravatar_id":"","url":"https://api.github.com/users/symfony","html_url":"https://github.com/symfony","followers_url":"https://api.github.com/users/symfony/followers","following_url":"https://api.github.com/users/symfony/following{/other_user}","gists_url":"https://api.github.com/users/symfony/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony/subscriptions","organizations_url":"https://api.github.com/users/symfony/orgs","repos_url":"https://api.github.com/users/symfony/repos","events_url":"https://api.github.com/users/symfony/events{/privacy}","received_events_url":"https://api.github.com/users/symfony/received_events","type":"Organization","site_admin":false},"repo":{"id":458058,"name":"symfony","full_name":"symfony/symfony","owner":{"login":"symfony","id":143937,"avatar_url":"https://avatars.githubusercontent.com/u/143937?v=3","gravatar_id":"","url":"https://api.github.com/users/symfony","html_url":"https://github.com/symfony","followers_url":"https://api.github.com/users/symfony/followers","following_url":"https://api.github.com/users/symfony/following{/other_user}","gists_url":"https://api.github.com/users/symfony/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony/subscriptions","organizations_url":"https://api.github.com/users/symfony/orgs","repos_url":"https://api.github.com/users/symfony/repos","events_url":"https://api.github.com/users/symfony/events{/privacy}","received_events_url":"https://api.github.com/users/symfony/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/symfony/symfony","description":"The Symfony PHP framework","fork":false,"url":"https://api.github.com/repos/symfony/symfony","forks_url":"https://api.github.com/repos/symfony/symfony/forks","keys_url":"https://api.github.com/repos/symfony/symfony/keys{/key_id}","collaborators_url":"https://api.github.com/repos/symfony/symfony/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/symfony/symfony/teams","hooks_url":"https://api.github.com/repos/symfony/symfony/hooks","issue_events_url":"https://api.github.com/repos/symfony/symfony/issues/events{/number}","events_url":"https://api.github.com/repos/symfony/symfony/events","assignees_url":"https://api.github.com/repos/symfony/symfony/assignees{/user}","branches_url":"https://api.github.com/repos/symfony/symfony/branches{/branch}","tags_url":"https://api.github.com/repos/symfony/symfony/tags","blobs_url":"https://api.github.com/repos/symfony/symfony/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/symfony/symfony/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/symfony/symfony/git/refs{/sha}","trees_url":"https://api.github.com/repos/symfony/symfony/git/trees{/sha}","statuses_url":"https://api.github.com/repos/symfony/symfony/statuses/{sha}","languages_url":"https://api.github.com/repos/symfony/symfony/languages","stargazers_url":"https://api.github.com/repos/symfony/symfony/stargazers","contributors_url":"https://api.github.com/repos/symfony/symfony/contributors","subscribers_url":"https://api.github.com/repos/symfony/symfony/subscribers","subscription_url":"https://api.github.com/repos/symfony/symfony/subscription","commits_url":"https://api.github.com/repos/symfony/symfony/commits{/sha}","git_commits_url":"https://api.github.com/repos/symfony/symfony/git/commits{/sha}","comments_url":"https://api.github.com/repos/symfony/symfony/comments{/number}","issue_comment_url":"https://api.github.com/repos/symfony/symfony/issues/comments{/number}","contents_url":"https://api.github.com/repos/symfony/symfony/contents/{+path}","compare_url":"https://api.github.com/repos/symfony/symfony/compare/{base}...{head}","merges_url":"https://api.github.com/repos/symfony/symfony/merges","archive_url":"https://api.github.com/repos/symfony/symfony/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/symfony/symfony/downloads","issues_url":"https://api.github.com/repos/symfony/symfony/issues{/number}","pulls_url":"https://api.github.com/repos/symfony/symfony/pulls{/number}","milestones_url":"https://api.github.com/repos/symfony/symfony/milestones{/number}","notifications_url":"https://api.github.com/repos/symfony/symfony/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/symfony/symfony/labels{/name}","releases_url":"https://api.github.com/repos/symfony/symfony/releases{/id}","deployments_url":"https://api.github.com/repos/symfony/symfony/deployments","created_at":"2010-01-04T14:21:21Z","updated_at":"2016-08-10T08:51:30Z","pushed_at":"2016-08-10T09:26:29Z","git_url":"git://github.com/symfony/symfony.git","ssh_url":"git@github.com:symfony/symfony.git","clone_url":"https://github.com/symfony/symfony.git","svn_url":"https://github.com/symfony/symfony","homepage":"symfony.com","size":131351,"stargazers_count":12752,"watchers_count":12752,"language":"PHP","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":4970,"mirror_url":null,"open_issues_count":733,"forks":4970,"open_issues":733,"watchers":12752,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/symfony/symfony/pulls/19382"},"html":{"href":"https://github.com/symfony/symfony/pull/19382"},"issue":{"href":"https://api.github.com/repos/symfony/symfony/issues/19382"},"comments":{"href":"https://api.github.com/repos/symfony/symfony/issues/19382/comments"},"review_comments":{"href":"https://api.github.com/repos/symfony/symfony/pulls/19382/comments"},"review_comment":{"href":"https://api.github.com/repos/symfony/symfony/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/symfony/symfony/pulls/19382/commits"},"statuses":{"href":"https://api.github.com/repos/symfony/symfony/statuses/36a1dd6427b57b32da0d3cd4674e9d790775cc3d"}}}}
{"actor":{"display_login":"lyrixx"}}