{"action":"created","comment":{"url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/pulls/comments/70110789","id":70110789,"diff_hunk":"@@ -0,0 +1,163 @@\n+/*\n+ * The MIT License\n+ *\n+ * Copyright 2016 CloudBees, Inc.\n+ *\n+ * Permission is hereby granted, free of charge, to any person obtaining a copy\n+ * of this software and associated documentation files (the \"Software\"), to deal\n+ * in the Software without restriction, including without limitation the rights\n+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+ * copies of the Software, and to permit persons to whom the Software is\n+ * furnished to do so, subject to the following conditions:\n+ *\n+ * The above copyright notice and this permission notice shall be included in\n+ * all copies or substantial portions of the Software.\n+ *\n+ * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n+ * THE SOFTWARE.\n+ */\n+\n+package org.jvnet.hudson.test;\n+\n+import hudson.util.RingBufferLogHandler;\n+import java.util.ArrayList;\n+import java.util.HashMap;\n+import java.util.List;\n+import java.util.Map;\n+import java.util.logging.ConsoleHandler;\n+import java.util.logging.Formatter;\n+import java.util.logging.Level;\n+import java.util.logging.LogRecord;\n+import java.util.logging.Logger;\n+import java.util.logging.SimpleFormatter;\n+import org.junit.ClassRule;\n+import org.junit.Rule;\n+import org.junit.rules.ExternalResource;\n+import org.junit.rules.RuleChain;\n+\n+/**\n+ * A test rule which allows you to easily enable one or more loggers for the duration of a test.\n+ * Call {@link #record(Class, Level)} or another overload for the rule to take effect.\n+ * <p>By default messages are merely printed to test output.\n+ * If you also want to examine them, call TODO\n+ * <p>To capture messages during Jenkins startup,\n+ * you may compose this with a {@link JenkinsRule} using a {@link RuleChain};\n+ * or use as a {@link ClassRule}.\n+ */\n+public class LoggerRule extends ExternalResource {\n+\n+    private final ConsoleHandler consoleHandler = new ConsoleHandler();\n+    private final Map<Logger,Level> loggers = new HashMap<Logger,Level>();\n+    // initialized iff capture is called:\n+    private RingBufferLogHandler ringHandler;\n+    private List<String> messages;\n+\n+    /**\n+     * Initializes the rule, by default not recording anything.\n+     */\n+    public LoggerRule() {\n+        consoleHandler.setLevel(Level.ALL);\n+    }\n+\n+    /**\n+     * Initializes log record capture, in addition to merely printing it.\n+     * This allows you to call {@link #getRecords} and/or {@link #getRecordsFormatted} later.\n+     * @param maximum the maximum number of records to keep (any further will be discarded)\n+     * @return this rule, for convenience\n+     */\n+    public LoggerRule capture(int maximum) {\n+        messages = new ArrayList<String>();\n+        ringHandler = new RingBufferLogHandler(maximum) {\n+            final Formatter f = new SimpleFormatter(); // placeholder instance for what should have been a static method perhaps\n+            @Override\n+            public synchronized void publish(LogRecord record) {\n+                super.publish(record);\n+                String message = f.formatMessage(record);\n+                Throwable x = record.getThrown();\n+                messages.add(message == null && x != null ? x.toString() : message);","path":"src/main/java/org/jvnet/hudson/test/LoggerRule.java","position":82,"original_position":82,"commit_id":"8e1094df0b0d8840d651b6fbe1a57f2171cdf2aa","original_commit_id":"bafd0305257faef88c0c80f1cd294eac6161173f","user":{"login":"jtnord","id":494726,"avatar_url":"https://avatars.githubusercontent.com/u/494726?v=3","gravatar_id":"","url":"https://api.github.com/users/jtnord","html_url":"https://github.com/jtnord","followers_url":"https://api.github.com/users/jtnord/followers","following_url":"https://api.github.com/users/jtnord/following{/other_user}","gists_url":"https://api.github.com/users/jtnord/gists{/gist_id}","starred_url":"https://api.github.com/users/jtnord/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jtnord/subscriptions","organizations_url":"https://api.github.com/users/jtnord/orgs","repos_url":"https://api.github.com/users/jtnord/repos","events_url":"https://api.github.com/users/jtnord/events{/privacy}","received_events_url":"https://api.github.com/users/jtnord/received_events","type":"User","site_admin":false},"body":"> I take it the unbounded nature is what you are expecting here.\r\n\r\nDid I miss something that was limiting the number of messages kept in the `ArrayList` rather than the ring buffer?","created_at":"2016-07-08T17:33:33Z","updated_at":"2016-07-08T17:33:33Z","html_url":"https://github.com/jenkinsci/jenkins-test-harness/pull/27#discussion_r70110789","pull_request_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/pulls/27","_links":{"self":{"href":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/pulls/comments/70110789"},"html":{"href":"https://github.com/jenkinsci/jenkins-test-harness/pull/27#discussion_r70110789"},"pull_request":{"href":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/pulls/27"}}},"pull_request":{"url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/pulls/27","id":76685604,"html_url":"https://github.com/jenkinsci/jenkins-test-harness/pull/27","diff_url":"https://github.com/jenkinsci/jenkins-test-harness/pull/27.diff","patch_url":"https://github.com/jenkinsci/jenkins-test-harness/pull/27.patch","issue_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/issues/27","number":27,"state":"open","locked":false,"title":"LoggerRule","user":{"login":"jglick","id":154109,"avatar_url":"https://avatars.githubusercontent.com/u/154109?v=3","gravatar_id":"","url":"https://api.github.com/users/jglick","html_url":"https://github.com/jglick","followers_url":"https://api.github.com/users/jglick/followers","following_url":"https://api.github.com/users/jglick/following{/other_user}","gists_url":"https://api.github.com/users/jglick/gists{/gist_id}","starred_url":"https://api.github.com/users/jglick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jglick/subscriptions","organizations_url":"https://api.github.com/users/jglick/orgs","repos_url":"https://api.github.com/users/jglick/repos","events_url":"https://api.github.com/users/jglick/events{/privacy}","received_events_url":"https://api.github.com/users/jglick/received_events","type":"User","site_admin":false},"body":"Should be self-explanatory.\r\n\r\n@reviewbybees","created_at":"2016-07-08T00:17:19Z","updated_at":"2016-07-08T17:33:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bc36ce348ac361e42b45743cd534f550d530c4d3","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/pulls/27/commits","review_comments_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/pulls/27/comments","review_comment_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/issues/27/comments","statuses_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/statuses/8e1094df0b0d8840d651b6fbe1a57f2171cdf2aa","head":{"label":"jglick:LoggerRule","ref":"LoggerRule","sha":"8e1094df0b0d8840d651b6fbe1a57f2171cdf2aa","user":{"login":"jglick","id":154109,"avatar_url":"https://avatars.githubusercontent.com/u/154109?v=3","gravatar_id":"","url":"https://api.github.com/users/jglick","html_url":"https://github.com/jglick","followers_url":"https://api.github.com/users/jglick/followers","following_url":"https://api.github.com/users/jglick/following{/other_user}","gists_url":"https://api.github.com/users/jglick/gists{/gist_id}","starred_url":"https://api.github.com/users/jglick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jglick/subscriptions","organizations_url":"https://api.github.com/users/jglick/orgs","repos_url":"https://api.github.com/users/jglick/repos","events_url":"https://api.github.com/users/jglick/events{/privacy}","received_events_url":"https://api.github.com/users/jglick/received_events","type":"User","site_admin":false},"repo":{"id":50138093,"name":"jenkins-test-harness","full_name":"jglick/jenkins-test-harness","owner":{"login":"jglick","id":154109,"avatar_url":"https://avatars.githubusercontent.com/u/154109?v=3","gravatar_id":"","url":"https://api.github.com/users/jglick","html_url":"https://github.com/jglick","followers_url":"https://api.github.com/users/jglick/followers","following_url":"https://api.github.com/users/jglick/following{/other_user}","gists_url":"https://api.github.com/users/jglick/gists{/gist_id}","starred_url":"https://api.github.com/users/jglick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jglick/subscriptions","organizations_url":"https://api.github.com/users/jglick/orgs","repos_url":"https://api.github.com/users/jglick/repos","events_url":"https://api.github.com/users/jglick/events{/privacy}","received_events_url":"https://api.github.com/users/jglick/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jglick/jenkins-test-harness","description":"","fork":true,"url":"https://api.github.com/repos/jglick/jenkins-test-harness","forks_url":"https://api.github.com/repos/jglick/jenkins-test-harness/forks","keys_url":"https://api.github.com/repos/jglick/jenkins-test-harness/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jglick/jenkins-test-harness/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jglick/jenkins-test-harness/teams","hooks_url":"https://api.github.com/repos/jglick/jenkins-test-harness/hooks","issue_events_url":"https://api.github.com/repos/jglick/jenkins-test-harness/issues/events{/number}","events_url":"https://api.github.com/repos/jglick/jenkins-test-harness/events","assignees_url":"https://api.github.com/repos/jglick/jenkins-test-harness/assignees{/user}","branches_url":"https://api.github.com/repos/jglick/jenkins-test-harness/branches{/branch}","tags_url":"https://api.github.com/repos/jglick/jenkins-test-harness/tags","blobs_url":"https://api.github.com/repos/jglick/jenkins-test-harness/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jglick/jenkins-test-harness/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jglick/jenkins-test-harness/git/refs{/sha}","trees_url":"https://api.github.com/repos/jglick/jenkins-test-harness/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jglick/jenkins-test-harness/statuses/{sha}","languages_url":"https://api.github.com/repos/jglick/jenkins-test-harness/languages","stargazers_url":"https://api.github.com/repos/jglick/jenkins-test-harness/stargazers","contributors_url":"https://api.github.com/repos/jglick/jenkins-test-harness/contributors","subscribers_url":"https://api.github.com/repos/jglick/jenkins-test-harness/subscribers","subscription_url":"https://api.github.com/repos/jglick/jenkins-test-harness/subscription","commits_url":"https://api.github.com/repos/jglick/jenkins-test-harness/commits{/sha}","git_commits_url":"https://api.github.com/repos/jglick/jenkins-test-harness/git/commits{/sha}","comments_url":"https://api.github.com/repos/jglick/jenkins-test-harness/comments{/number}","issue_comment_url":"https://api.github.com/repos/jglick/jenkins-test-harness/issues/comments{/number}","contents_url":"https://api.github.com/repos/jglick/jenkins-test-harness/contents/{+path}","compare_url":"https://api.github.com/repos/jglick/jenkins-test-harness/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jglick/jenkins-test-harness/merges","archive_url":"https://api.github.com/repos/jglick/jenkins-test-harness/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jglick/jenkins-test-harness/downloads","issues_url":"https://api.github.com/repos/jglick/jenkins-test-harness/issues{/number}","pulls_url":"https://api.github.com/repos/jglick/jenkins-test-harness/pulls{/number}","milestones_url":"https://api.github.com/repos/jglick/jenkins-test-harness/milestones{/number}","notifications_url":"https://api.github.com/repos/jglick/jenkins-test-harness/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jglick/jenkins-test-harness/labels{/name}","releases_url":"https://api.github.com/repos/jglick/jenkins-test-harness/releases{/id}","deployments_url":"https://api.github.com/repos/jglick/jenkins-test-harness/deployments","created_at":"2016-01-21T21:30:21Z","updated_at":"2016-01-21T21:30:22Z","pushed_at":"2016-07-08T15:25:53Z","git_url":"git://github.com/jglick/jenkins-test-harness.git","ssh_url":"git@github.com:jglick/jenkins-test-harness.git","clone_url":"https://github.com/jglick/jenkins-test-harness.git","svn_url":"https://github.com/jglick/jenkins-test-harness","homepage":"","size":27347,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"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":"jenkinsci:master","ref":"master","sha":"1b387d7a5226256352b135f21df5edcb38843387","user":{"login":"jenkinsci","id":107424,"avatar_url":"https://avatars.githubusercontent.com/u/107424?v=3","gravatar_id":"","url":"https://api.github.com/users/jenkinsci","html_url":"https://github.com/jenkinsci","followers_url":"https://api.github.com/users/jenkinsci/followers","following_url":"https://api.github.com/users/jenkinsci/following{/other_user}","gists_url":"https://api.github.com/users/jenkinsci/gists{/gist_id}","starred_url":"https://api.github.com/users/jenkinsci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jenkinsci/subscriptions","organizations_url":"https://api.github.com/users/jenkinsci/orgs","repos_url":"https://api.github.com/users/jenkinsci/repos","events_url":"https://api.github.com/users/jenkinsci/events{/privacy}","received_events_url":"https://api.github.com/users/jenkinsci/received_events","type":"Organization","site_admin":false},"repo":{"id":49739417,"name":"jenkins-test-harness","full_name":"jenkinsci/jenkins-test-harness","owner":{"login":"jenkinsci","id":107424,"avatar_url":"https://avatars.githubusercontent.com/u/107424?v=3","gravatar_id":"","url":"https://api.github.com/users/jenkinsci","html_url":"https://github.com/jenkinsci","followers_url":"https://api.github.com/users/jenkinsci/followers","following_url":"https://api.github.com/users/jenkinsci/following{/other_user}","gists_url":"https://api.github.com/users/jenkinsci/gists{/gist_id}","starred_url":"https://api.github.com/users/jenkinsci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jenkinsci/subscriptions","organizations_url":"https://api.github.com/users/jenkinsci/orgs","repos_url":"https://api.github.com/users/jenkinsci/repos","events_url":"https://api.github.com/users/jenkinsci/events{/privacy}","received_events_url":"https://api.github.com/users/jenkinsci/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/jenkinsci/jenkins-test-harness","description":"Unit test framework for Jenkins core and its plugins","fork":false,"url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness","forks_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/forks","keys_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/teams","hooks_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/hooks","issue_events_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/issues/events{/number}","events_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/events","assignees_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/assignees{/user}","branches_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/branches{/branch}","tags_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/tags","blobs_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/git/refs{/sha}","trees_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/statuses/{sha}","languages_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/languages","stargazers_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/stargazers","contributors_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/contributors","subscribers_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/subscribers","subscription_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/subscription","commits_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/commits{/sha}","git_commits_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/git/commits{/sha}","comments_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/comments{/number}","issue_comment_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/issues/comments{/number}","contents_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/contents/{+path}","compare_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/merges","archive_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/downloads","issues_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/issues{/number}","pulls_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/pulls{/number}","milestones_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/milestones{/number}","notifications_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/labels{/name}","releases_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/releases{/id}","deployments_url":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/deployments","created_at":"2016-01-15T19:11:45Z","updated_at":"2016-05-31T10:18:09Z","pushed_at":"2016-07-08T15:25:53Z","git_url":"git://github.com/jenkinsci/jenkins-test-harness.git","ssh_url":"git@github.com:jenkinsci/jenkins-test-harness.git","clone_url":"https://github.com/jenkinsci/jenkins-test-harness.git","svn_url":"https://github.com/jenkinsci/jenkins-test-harness","homepage":"https://wiki.jenkins-ci.org/display/JENKINS/Unit+Test","size":27348,"stargazers_count":5,"watchers_count":5,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":12,"mirror_url":null,"open_issues_count":2,"forks":12,"open_issues":2,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/pulls/27"},"html":{"href":"https://github.com/jenkinsci/jenkins-test-harness/pull/27"},"issue":{"href":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/issues/27"},"comments":{"href":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/issues/27/comments"},"review_comments":{"href":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/pulls/27/comments"},"review_comment":{"href":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/pulls/27/commits"},"statuses":{"href":"https://api.github.com/repos/jenkinsci/jenkins-test-harness/statuses/8e1094df0b0d8840d651b6fbe1a57f2171cdf2aa"}}}}
{"actor":{"display_login":"jtnord"}}