{"action":"created","comment":{"url":"https://api.github.com/repos/caskdata/cdap/pulls/comments/28352528","id":28352528,"diff_hunk":"@@ -16,23 +16,98 @@\n \n package co.cask.cdap.logging.appender;\n \n+import ch.qos.logback.classic.LoggerContext;\n+import ch.qos.logback.core.util.StatusPrinter;\n+import co.cask.cdap.common.logging.ApplicationLoggingContext;\n import co.cask.cdap.common.logging.LoggingContext;\n+import co.cask.cdap.common.logging.LoggingContextAccessor;\n+import co.cask.cdap.common.logging.NamespaceLoggingContext;\n+import co.cask.cdap.logging.context.LoggingContextHelper;\n import co.cask.cdap.logging.filter.Filter;\n import co.cask.cdap.logging.read.Callback;\n import co.cask.cdap.logging.read.LogEvent;\n import co.cask.cdap.logging.read.LogOffset;\n import co.cask.cdap.logging.read.LogReader;\n+import com.google.common.base.Function;\n+import com.google.common.collect.Maps;\n import org.junit.Assert;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n \n+import java.io.ByteArrayOutputStream;\n+import java.io.PrintStream;\n import java.util.ArrayList;\n import java.util.Collections;\n import java.util.List;\n+import java.util.Map;\n import java.util.concurrent.CountDownLatch;\n \n /**\n  *\n  */\n public class LoggingTester {\n+  public void generateLogs(Logger logger, LoggingContext loggingContextNs1) {\n+    Exception e1 = new Exception(\"Test Exception1\");\n+    Exception e2 = new Exception(\"Test Exception2\", e1);\n+\n+    LoggingContext loggingContextNs2 =\n+      replaceTag(loggingContextNs1,\n+                 new Entry(NamespaceLoggingContext.TAG_NAMESPACE_ID, getNamespace2(loggingContextNs1)));\n+\n+    LoggingContextAccessor.setLoggingContext(loggingContextNs2);\n+    for (int i = 0; i < 40; ++i) {\n+      logger.warn(\"NS_2 Test log message {} {} {}\", i, \"arg1\", \"arg2\", e2);\n+    }\n+\n+    LoggingContextAccessor.setLoggingContext(loggingContextNs1);\n+    for (int i = 0; i < 20; ++i) {\n+      logger.warn(\"Test log message {} {} {}\", i, \"arg1\", \"arg2\", e2);\n+    }\n+\n+    LoggingContextAccessor.setLoggingContext(loggingContextNs2);\n+    for (int i = 40; i < 80; ++i) {\n+      logger.warn(\"NS_2 Test log message {} {} {}\", i, \"arg1\", \"arg2\", e2);\n+    }\n+\n+    LoggingContextAccessor.setLoggingContext(loggingContextNs1);\n+    for (int i = 20; i < 40; ++i) {\n+      logger.warn(\"Test log message {} {} {}\", i, \"arg1\", \"arg2\", e2);\n+    }\n+\n+    LoggingContextAccessor.setLoggingContext(loggingContextNs1);\n+    for (int i = 40; i < 60; ++i) {\n+      logger.warn(\"Test log message {} {} {}\", i, \"arg1\", \"arg2\", e2);\n+    }\n+\n+    // Add logs with a different runid\n+    LoggingContextAccessor.setLoggingContext(\n+      replaceTag(loggingContextNs1, new Entry(ApplicationLoggingContext.TAG_RUNID_ID, \"RUN2\")));\n+    for (int i = 40; i < 60; ++i) {\n+      logger.warn(\"RUN2 Test log message {} {} {}\", i, \"arg1\", \"arg2\", e2);\n+    }\n+\n+    // Add logs with null runid and null instanceid\n+    LoggingContextAccessor.setLoggingContext(\n+      replaceTag(loggingContextNs1, new Entry(ApplicationLoggingContext.TAG_RUNID_ID, null),\n+                 new Entry(ApplicationLoggingContext.TAG_INSTANCE_ID, null)));\n+    for (int i = 40; i < 60; ++i) {\n+      logger.warn(\"NULL Test log message {} {} {}\", i, \"arg1\", \"arg2\", e2);\n+    }\n+\n+    // Check with null runId and null instanceId\n+    LoggingContextAccessor.setLoggingContext(\n+      replaceTag(loggingContextNs2, new Entry(ApplicationLoggingContext.TAG_RUNID_ID, null),\n+                 new Entry(ApplicationLoggingContext.TAG_INSTANCE_ID, null)));\n+    for (int i = 80; i < 120; ++i) {\n+      logger.warn(\"NS_2 Test log message {} {} {}\", i, \"arg1\", \"arg2\", e2);\n+    }\n+\n+    ByteArrayOutputStream bos = new ByteArrayOutputStream();\n+    StatusPrinter.setPrintStream(new PrintStream(bos));\n+    StatusPrinter.print((LoggerContext) LoggerFactory.getILoggerFactory());\n+    System.out.println(bos.toString());","path":"cdap-watchdog/src/test/java/co/cask/cdap/logging/appender/LoggingTester.java","position":93,"original_position":93,"commit_id":"26c779b72389616f927a8b5df077625dbeb5a5d2","original_commit_id":"26c779b72389616f927a8b5df077625dbeb5a5d2","user":{"login":"bdmogal","id":3895099,"avatar_url":"https://avatars.githubusercontent.com/u/3895099?v=3","gravatar_id":"","url":"https://api.github.com/users/bdmogal","html_url":"https://github.com/bdmogal","followers_url":"https://api.github.com/users/bdmogal/followers","following_url":"https://api.github.com/users/bdmogal/following{/other_user}","gists_url":"https://api.github.com/users/bdmogal/gists{/gist_id}","starred_url":"https://api.github.com/users/bdmogal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bdmogal/subscriptions","organizations_url":"https://api.github.com/users/bdmogal/orgs","repos_url":"https://api.github.com/users/bdmogal/repos","events_url":"https://api.github.com/users/bdmogal/events{/privacy}","received_events_url":"https://api.github.com/users/bdmogal/received_events","type":"User","site_admin":false},"body":"stdout? Is this intentional?","created_at":"2015-04-14T18:00:57Z","updated_at":"2015-04-14T18:00:57Z","html_url":"https://github.com/caskdata/cdap/pull/2014#discussion_r28352528","pull_request_url":"https://api.github.com/repos/caskdata/cdap/pulls/2014","_links":{"self":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/comments/28352528"},"html":{"href":"https://github.com/caskdata/cdap/pull/2014#discussion_r28352528"},"pull_request":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/2014"}}},"pull_request":{"url":"https://api.github.com/repos/caskdata/cdap/pulls/2014","id":33203760,"html_url":"https://github.com/caskdata/cdap/pull/2014","diff_url":"https://github.com/caskdata/cdap/pull/2014.diff","patch_url":"https://github.com/caskdata/cdap/pull/2014.patch","issue_url":"https://api.github.com/repos/caskdata/cdap/issues/2014","number":2014,"state":"open","locked":false,"title":"Adding endpoint to fetch logs by runid","user":{"login":"poornachandra","id":3181212,"avatar_url":"https://avatars.githubusercontent.com/u/3181212?v=3","gravatar_id":"","url":"https://api.github.com/users/poornachandra","html_url":"https://github.com/poornachandra","followers_url":"https://api.github.com/users/poornachandra/followers","following_url":"https://api.github.com/users/poornachandra/following{/other_user}","gists_url":"https://api.github.com/users/poornachandra/gists{/gist_id}","starred_url":"https://api.github.com/users/poornachandra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/poornachandra/subscriptions","organizations_url":"https://api.github.com/users/poornachandra/orgs","repos_url":"https://api.github.com/users/poornachandra/repos","events_url":"https://api.github.com/users/poornachandra/events{/privacy}","received_events_url":"https://api.github.com/users/poornachandra/received_events","type":"User","site_admin":false},"body":"JIRA https://issues.cask.co/browse/CDAP-2051\r\n\r\nAdding log endpoints to fetch logs by run-id -\r\n* `/namespaces/{namespace-id}/apps/{app-id}/{program-type}/{program-id}/runs/{run-id}/logs`\r\n* `/namespaces/{namespace-id}/apps/{app-id}/{program-type}/{program-id}/runs/{run-id}/logs/next`\r\n* `/namespaces/{namespace-id}/apps/{app-id}/{program-type}/{program-id}/runs/{run-id}/logs/prev`\r\n* `/namespaces/{namespace-id}/adapters/{adapter-id}/runs/{run-id}/logs`\r\n\r\nAlso refactored test cases.\r\n\r\n","created_at":"2015-04-13T21:08:54Z","updated_at":"2015-04-14T18:00:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"693d7df1a6544bd92949a4a65d8146e8888857cd","assignee":{"login":"bdmogal","id":3895099,"avatar_url":"https://avatars.githubusercontent.com/u/3895099?v=3","gravatar_id":"","url":"https://api.github.com/users/bdmogal","html_url":"https://github.com/bdmogal","followers_url":"https://api.github.com/users/bdmogal/followers","following_url":"https://api.github.com/users/bdmogal/following{/other_user}","gists_url":"https://api.github.com/users/bdmogal/gists{/gist_id}","starred_url":"https://api.github.com/users/bdmogal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bdmogal/subscriptions","organizations_url":"https://api.github.com/users/bdmogal/orgs","repos_url":"https://api.github.com/users/bdmogal/repos","events_url":"https://api.github.com/users/bdmogal/events{/privacy}","received_events_url":"https://api.github.com/users/bdmogal/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/caskdata/cdap/milestones/4","html_url":"https://github.com/caskdata/cdap/milestones/3.0.0","labels_url":"https://api.github.com/repos/caskdata/cdap/milestones/4/labels","id":990469,"number":4,"title":"3.0.0","description":null,"creator":{"login":"jwang47","id":1084704,"avatar_url":"https://avatars.githubusercontent.com/u/1084704?v=3","gravatar_id":"","url":"https://api.github.com/users/jwang47","html_url":"https://github.com/jwang47","followers_url":"https://api.github.com/users/jwang47/followers","following_url":"https://api.github.com/users/jwang47/following{/other_user}","gists_url":"https://api.github.com/users/jwang47/gists{/gist_id}","starred_url":"https://api.github.com/users/jwang47/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwang47/subscriptions","organizations_url":"https://api.github.com/users/jwang47/orgs","repos_url":"https://api.github.com/users/jwang47/repos","events_url":"https://api.github.com/users/jwang47/events{/privacy}","received_events_url":"https://api.github.com/users/jwang47/received_events","type":"User","site_admin":false},"open_issues":7,"closed_issues":125,"state":"open","created_at":"2015-02-23T00:07:53Z","updated_at":"2015-04-14T01:35:33Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/caskdata/cdap/pulls/2014/commits","review_comments_url":"https://api.github.com/repos/caskdata/cdap/pulls/2014/comments","review_comment_url":"https://api.github.com/repos/caskdata/cdap/pulls/comments{/number}","comments_url":"https://api.github.com/repos/caskdata/cdap/issues/2014/comments","statuses_url":"https://api.github.com/repos/caskdata/cdap/statuses/26c779b72389616f927a8b5df077625dbeb5a5d2","head":{"label":"caskdata:feature/runid-log-endpoint","ref":"feature/runid-log-endpoint","sha":"26c779b72389616f927a8b5df077625dbeb5a5d2","user":{"login":"caskdata","id":8123023,"avatar_url":"https://avatars.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://avatars.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}","created_at":"2014-08-02T09:00:10Z","updated_at":"2015-04-14T17:33:31Z","pushed_at":"2015-04-14T17:43:59Z","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":"http://cdap.io","size":840276,"stargazers_count":41,"watchers_count":41,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":12,"mirror_url":null,"open_issues_count":14,"forks":12,"open_issues":14,"watchers":41,"default_branch":"develop"}},"base":{"label":"caskdata:develop","ref":"develop","sha":"995991db56e7134ed5d0fd33e03e4916b6ed183b","user":{"login":"caskdata","id":8123023,"avatar_url":"https://avatars.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://avatars.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}","created_at":"2014-08-02T09:00:10Z","updated_at":"2015-04-14T17:33:31Z","pushed_at":"2015-04-14T17:43:59Z","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":"http://cdap.io","size":840276,"stargazers_count":41,"watchers_count":41,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":12,"mirror_url":null,"open_issues_count":14,"forks":12,"open_issues":14,"watchers":41,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/2014"},"html":{"href":"https://github.com/caskdata/cdap/pull/2014"},"issue":{"href":"https://api.github.com/repos/caskdata/cdap/issues/2014"},"comments":{"href":"https://api.github.com/repos/caskdata/cdap/issues/2014/comments"},"review_comments":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/2014/comments"},"review_comment":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/caskdata/cdap/pulls/2014/commits"},"statuses":{"href":"https://api.github.com/repos/caskdata/cdap/statuses/26c779b72389616f927a8b5df077625dbeb5a5d2"}}}}