{"action":"created","comment":{"url":"https://api.github.com/repos/caskdata/cdap/pulls/comments/114057965","pull_request_review_id":35500912,"id":114057965,"diff_hunk":"@@ -38,16 +41,30 @@\n    *         logging context object instance.\n    * </p>\n    * @param context context to set\n+   * @return Cancellable that can be used to revert the logging context and MDC Map to its original value\n    */\n-  public static void setLoggingContext(LoggingContext context) {\n+  public static Cancellable setLoggingContext(LoggingContext context) {\n+    final LoggingContext saveLoggingContext = loggingContext.get();\n+    final Map saveContextMap = MDC.getCopyOfContextMap();\n+    final Thread saveCurrentThread = Thread.currentThread();\n+\n     loggingContext.set(context);\n     try {\n       // Also copy context tags to MDC\n       MDC.setContextMap(context.getSystemTagsAsString());\n     } catch (IllegalStateException e) {\n-      // MDC will throw this if there is no valid binding. Normally this should happen, but in case it does,\n+      // MDC will throw this if there is no valid binding. Normally this shouldn't happen, but in case it does,\n       // we'll just ignore it as it doesn't affect platform logic at all as we always use loggingContext.\n     }\n+    return new Cancellable() {\n+      @Override\n+      public void cancel() {\n+        if (Thread.currentThread() == saveCurrentThread) {","path":"cdap-common/src/main/java/co/cask/cdap/common/logging/LoggingContextAccessor.java","position":36,"original_position":36,"commit_id":"a291c0be4e52bc1865f9618d820207ded2338d73","original_commit_id":"a291c0be4e52bc1865f9618d820207ded2338d73","user":{"login":"chtyim","id":885032,"avatar_url":"https://avatars2.githubusercontent.com/u/885032?v=3","gravatar_id":"","url":"https://api.github.com/users/chtyim","html_url":"https://github.com/chtyim","followers_url":"https://api.github.com/users/chtyim/followers","following_url":"https://api.github.com/users/chtyim/following{/other_user}","gists_url":"https://api.github.com/users/chtyim/gists{/gist_id}","starred_url":"https://api.github.com/users/chtyim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chtyim/subscriptions","organizations_url":"https://api.github.com/users/chtyim/orgs","repos_url":"https://api.github.com/users/chtyim/repos","events_url":"https://api.github.com/users/chtyim/events{/privacy}","received_events_url":"https://api.github.com/users/chtyim/received_events","type":"User","site_admin":false},"body":"The cancellable should only be cancel once.\r\n\r\n```java\r\nreturn new Cancellable() {\r\n  private boolean cancelled;\r\n\r\n  @Override\r\n  public void cancel() {\r\n    if (Thread.currentThread() == saveCurrentThread && !cancelled) {\r\n      cancelled = true;\r\n      ...\r\n    }\r\n  }\r\n};\r\n```","created_at":"2017-04-29T17:31:42Z","updated_at":"2017-04-29T17:31:50Z","html_url":"https://github.com/caskdata/cdap/pull/8646#discussion_r114057965","pull_request_url":"https://api.github.com/repos/caskdata/cdap/pulls/8646","_links":{"self":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/comments/114057965"},"html":{"href":"https://github.com/caskdata/cdap/pull/8646#discussion_r114057965"},"pull_request":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/8646"}}},"pull_request":{"url":"https://api.github.com/repos/caskdata/cdap/pulls/8646","id":117089235,"html_url":"https://github.com/caskdata/cdap/pull/8646","diff_url":"https://github.com/caskdata/cdap/pull/8646.diff","patch_url":"https://github.com/caskdata/cdap/pull/8646.patch","issue_url":"https://api.github.com/repos/caskdata/cdap/issues/8646","number":8646,"state":"open","locked":false,"title":"Add program start log with logging context","user":{"login":"deepakwadhwani","id":22896289,"avatar_url":"https://avatars0.githubusercontent.com/u/22896289?v=3","gravatar_id":"","url":"https://api.github.com/users/deepakwadhwani","html_url":"https://github.com/deepakwadhwani","followers_url":"https://api.github.com/users/deepakwadhwani/followers","following_url":"https://api.github.com/users/deepakwadhwani/following{/other_user}","gists_url":"https://api.github.com/users/deepakwadhwani/gists{/gist_id}","starred_url":"https://api.github.com/users/deepakwadhwani/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deepakwadhwani/subscriptions","organizations_url":"https://api.github.com/users/deepakwadhwani/orgs","repos_url":"https://api.github.com/users/deepakwadhwani/repos","events_url":"https://api.github.com/users/deepakwadhwani/events{/privacy}","received_events_url":"https://api.github.com/users/deepakwadhwani/received_events","type":"User","site_admin":false},"body":"CDAP-9321: Add Start log for all programs with logging context so that it shows in the Program logs. \r\nThis PR only adds a \"starting\" log for all programs. More log cleanups and error reporting changes to follow. ","created_at":"2017-04-22T00:55:59Z","updated_at":"2017-04-29T17:31:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e318b84e18178c0dc3db824c96feb87410a5381e","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/caskdata/cdap/pulls/8646/commits","review_comments_url":"https://api.github.com/repos/caskdata/cdap/pulls/8646/comments","review_comment_url":"https://api.github.com/repos/caskdata/cdap/pulls/comments{/number}","comments_url":"https://api.github.com/repos/caskdata/cdap/issues/8646/comments","statuses_url":"https://api.github.com/repos/caskdata/cdap/statuses/a291c0be4e52bc1865f9618d820207ded2338d73","head":{"label":"caskdata:feature/programuserlogs","ref":"feature/programuserlogs","sha":"a291c0be4e52bc1865f9618d820207ded2338d73","user":{"login":"caskdata","id":8123023,"avatar_url":"https://avatars1.githubusercontent.com/u/8123023?v=3","gravatar_id":"","url":"https://api.github.com/users/caskdata","html_url":"https://github.com/caskdata","followers_url":"https://api.github.com/users/caskdata/followers","following_url":"https://api.github.com/users/caskdata/following{/other_user}","gists_url":"https://api.github.com/users/caskdata/gists{/gist_id}","starred_url":"https://api.github.com/users/caskdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caskdata/subscriptions","organizations_url":"https://api.github.com/users/caskdata/orgs","repos_url":"https://api.github.com/users/caskdata/repos","events_url":"https://api.github.com/users/caskdata/events{/privacy}","received_events_url":"https://api.github.com/users/caskdata/received_events","type":"Organization","site_admin":false},"repo":{"id":22542759,"name":"cdap","full_name":"caskdata/cdap","owner":{"login":"caskdata","id":8123023,"avatar_url":"https://avatars1.githubusercontent.com/u/8123023?v=3","gravatar_id":"","url":"https://api.github.com/users/caskdata","html_url":"https://github.com/caskdata","followers_url":"https://api.github.com/users/caskdata/followers","following_url":"https://api.github.com/users/caskdata/following{/other_user}","gists_url":"https://api.github.com/users/caskdata/gists{/gist_id}","starred_url":"https://api.github.com/users/caskdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caskdata/subscriptions","organizations_url":"https://api.github.com/users/caskdata/orgs","repos_url":"https://api.github.com/users/caskdata/repos","events_url":"https://api.github.com/users/caskdata/events{/privacy}","received_events_url":"https://api.github.com/users/caskdata/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/caskdata/cdap","description":"Cask Data Application Platform (CDAP)","fork":false,"url":"https://api.github.com/repos/caskdata/cdap","forks_url":"https://api.github.com/repos/caskdata/cdap/forks","keys_url":"https://api.github.com/repos/caskdata/cdap/keys{/key_id}","collaborators_url":"https://api.github.com/repos/caskdata/cdap/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/caskdata/cdap/teams","hooks_url":"https://api.github.com/repos/caskdata/cdap/hooks","issue_events_url":"https://api.github.com/repos/caskdata/cdap/issues/events{/number}","events_url":"https://api.github.com/repos/caskdata/cdap/events","assignees_url":"https://api.github.com/repos/caskdata/cdap/assignees{/user}","branches_url":"https://api.github.com/repos/caskdata/cdap/branches{/branch}","tags_url":"https://api.github.com/repos/caskdata/cdap/tags","blobs_url":"https://api.github.com/repos/caskdata/cdap/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/caskdata/cdap/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/caskdata/cdap/git/refs{/sha}","trees_url":"https://api.github.com/repos/caskdata/cdap/git/trees{/sha}","statuses_url":"https://api.github.com/repos/caskdata/cdap/statuses/{sha}","languages_url":"https://api.github.com/repos/caskdata/cdap/languages","stargazers_url":"https://api.github.com/repos/caskdata/cdap/stargazers","contributors_url":"https://api.github.com/repos/caskdata/cdap/contributors","subscribers_url":"https://api.github.com/repos/caskdata/cdap/subscribers","subscription_url":"https://api.github.com/repos/caskdata/cdap/subscription","commits_url":"https://api.github.com/repos/caskdata/cdap/commits{/sha}","git_commits_url":"https://api.github.com/repos/caskdata/cdap/git/commits{/sha}","comments_url":"https://api.github.com/repos/caskdata/cdap/comments{/number}","issue_comment_url":"https://api.github.com/repos/caskdata/cdap/issues/comments{/number}","contents_url":"https://api.github.com/repos/caskdata/cdap/contents/{+path}","compare_url":"https://api.github.com/repos/caskdata/cdap/compare/{base}...{head}","merges_url":"https://api.github.com/repos/caskdata/cdap/merges","archive_url":"https://api.github.com/repos/caskdata/cdap/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/caskdata/cdap/downloads","issues_url":"https://api.github.com/repos/caskdata/cdap/issues{/number}","pulls_url":"https://api.github.com/repos/caskdata/cdap/pulls{/number}","milestones_url":"https://api.github.com/repos/caskdata/cdap/milestones{/number}","notifications_url":"https://api.github.com/repos/caskdata/cdap/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/caskdata/cdap/labels{/name}","releases_url":"https://api.github.com/repos/caskdata/cdap/releases{/id}","deployments_url":"https://api.github.com/repos/caskdata/cdap/deployments","created_at":"2014-08-02T09:00:10Z","updated_at":"2017-04-27T09:17:01Z","pushed_at":"2017-04-29T17:28:04Z","git_url":"git://github.com/caskdata/cdap.git","ssh_url":"git@github.com:caskdata/cdap.git","clone_url":"https://github.com/caskdata/cdap.git","svn_url":"https://github.com/caskdata/cdap","homepage":"","size":495264,"stargazers_count":173,"watchers_count":173,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":81,"mirror_url":null,"open_issues_count":20,"forks":81,"open_issues":20,"watchers":173,"default_branch":"develop"}},"base":{"label":"caskdata:develop","ref":"develop","sha":"5ef2c565bb26760dec9736b2e3144e0096038e63","user":{"login":"caskdata","id":8123023,"avatar_url":"https://avatars1.githubusercontent.com/u/8123023?v=3","gravatar_id":"","url":"https://api.github.com/users/caskdata","html_url":"https://github.com/caskdata","followers_url":"https://api.github.com/users/caskdata/followers","following_url":"https://api.github.com/users/caskdata/following{/other_user}","gists_url":"https://api.github.com/users/caskdata/gists{/gist_id}","starred_url":"https://api.github.com/users/caskdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caskdata/subscriptions","organizations_url":"https://api.github.com/users/caskdata/orgs","repos_url":"https://api.github.com/users/caskdata/repos","events_url":"https://api.github.com/users/caskdata/events{/privacy}","received_events_url":"https://api.github.com/users/caskdata/received_events","type":"Organization","site_admin":false},"repo":{"id":22542759,"name":"cdap","full_name":"caskdata/cdap","owner":{"login":"caskdata","id":8123023,"avatar_url":"https://avatars1.githubusercontent.com/u/8123023?v=3","gravatar_id":"","url":"https://api.github.com/users/caskdata","html_url":"https://github.com/caskdata","followers_url":"https://api.github.com/users/caskdata/followers","following_url":"https://api.github.com/users/caskdata/following{/other_user}","gists_url":"https://api.github.com/users/caskdata/gists{/gist_id}","starred_url":"https://api.github.com/users/caskdata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caskdata/subscriptions","organizations_url":"https://api.github.com/users/caskdata/orgs","repos_url":"https://api.github.com/users/caskdata/repos","events_url":"https://api.github.com/users/caskdata/events{/privacy}","received_events_url":"https://api.github.com/users/caskdata/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/caskdata/cdap","description":"Cask Data Application Platform (CDAP)","fork":false,"url":"https://api.github.com/repos/caskdata/cdap","forks_url":"https://api.github.com/repos/caskdata/cdap/forks","keys_url":"https://api.github.com/repos/caskdata/cdap/keys{/key_id}","collaborators_url":"https://api.github.com/repos/caskdata/cdap/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/caskdata/cdap/teams","hooks_url":"https://api.github.com/repos/caskdata/cdap/hooks","issue_events_url":"https://api.github.com/repos/caskdata/cdap/issues/events{/number}","events_url":"https://api.github.com/repos/caskdata/cdap/events","assignees_url":"https://api.github.com/repos/caskdata/cdap/assignees{/user}","branches_url":"https://api.github.com/repos/caskdata/cdap/branches{/branch}","tags_url":"https://api.github.com/repos/caskdata/cdap/tags","blobs_url":"https://api.github.com/repos/caskdata/cdap/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/caskdata/cdap/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/caskdata/cdap/git/refs{/sha}","trees_url":"https://api.github.com/repos/caskdata/cdap/git/trees{/sha}","statuses_url":"https://api.github.com/repos/caskdata/cdap/statuses/{sha}","languages_url":"https://api.github.com/repos/caskdata/cdap/languages","stargazers_url":"https://api.github.com/repos/caskdata/cdap/stargazers","contributors_url":"https://api.github.com/repos/caskdata/cdap/contributors","subscribers_url":"https://api.github.com/repos/caskdata/cdap/subscribers","subscription_url":"https://api.github.com/repos/caskdata/cdap/subscription","commits_url":"https://api.github.com/repos/caskdata/cdap/commits{/sha}","git_commits_url":"https://api.github.com/repos/caskdata/cdap/git/commits{/sha}","comments_url":"https://api.github.com/repos/caskdata/cdap/comments{/number}","issue_comment_url":"https://api.github.com/repos/caskdata/cdap/issues/comments{/number}","contents_url":"https://api.github.com/repos/caskdata/cdap/contents/{+path}","compare_url":"https://api.github.com/repos/caskdata/cdap/compare/{base}...{head}","merges_url":"https://api.github.com/repos/caskdata/cdap/merges","archive_url":"https://api.github.com/repos/caskdata/cdap/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/caskdata/cdap/downloads","issues_url":"https://api.github.com/repos/caskdata/cdap/issues{/number}","pulls_url":"https://api.github.com/repos/caskdata/cdap/pulls{/number}","milestones_url":"https://api.github.com/repos/caskdata/cdap/milestones{/number}","notifications_url":"https://api.github.com/repos/caskdata/cdap/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/caskdata/cdap/labels{/name}","releases_url":"https://api.github.com/repos/caskdata/cdap/releases{/id}","deployments_url":"https://api.github.com/repos/caskdata/cdap/deployments","created_at":"2014-08-02T09:00:10Z","updated_at":"2017-04-27T09:17:01Z","pushed_at":"2017-04-29T17:28:04Z","git_url":"git://github.com/caskdata/cdap.git","ssh_url":"git@github.com:caskdata/cdap.git","clone_url":"https://github.com/caskdata/cdap.git","svn_url":"https://github.com/caskdata/cdap","homepage":"","size":495264,"stargazers_count":173,"watchers_count":173,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":81,"mirror_url":null,"open_issues_count":20,"forks":81,"open_issues":20,"watchers":173,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/8646"},"html":{"href":"https://github.com/caskdata/cdap/pull/8646"},"issue":{"href":"https://api.github.com/repos/caskdata/cdap/issues/8646"},"comments":{"href":"https://api.github.com/repos/caskdata/cdap/issues/8646/comments"},"review_comments":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/8646/comments"},"review_comment":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/8646/commits"},"statuses":{"href":"https://api.github.com/repos/caskdata/cdap/statuses/a291c0be4e52bc1865f9618d820207ded2338d73"}}}}
{"actor":{"display_login":"chtyim"}}