diff --git a/core/src/main/java/hudson/logging/LogRecorder.java b/core/src/main/java/hudson/logging/LogRecorder.java index 43b4cb4562fab9b04f6e587c958a411a55dca9df..2299a74027b72e8d7ca28c79d1eef10e310b8cd9 100644 --- a/core/src/main/java/hudson/logging/LogRecorder.java +++ b/core/src/main/java/hudson/logging/LogRecorder.java @@ -297,6 +297,12 @@ public class LogRecorder extends AbstractModelObject implements Saveable { rsp.sendRedirect2(redirect); } + @RequirePOST + public void doClear(StaplerRequest req, StaplerResponse rsp) throws IOException { + handler.clear(); + rsp.sendRedirect2("."); + } + /** * Loads the settings from a file. */ diff --git a/core/src/main/java/hudson/util/RingBufferLogHandler.java b/core/src/main/java/hudson/util/RingBufferLogHandler.java index c7839d47ff74c7686821b71b1bac80e1cf4db006..19f48053d395983518ed4d201736ce4b9a52abe9 100644 --- a/core/src/main/java/hudson/util/RingBufferLogHandler.java +++ b/core/src/main/java/hudson/util/RingBufferLogHandler.java @@ -57,6 +57,11 @@ public class RingBufferLogHandler extends Handler { } } + public synchronized void clear() { + size = 0; + start = 0; + } + /** * Returns the list view of {@link LogRecord}s in the ring buffer. * diff --git a/core/src/main/resources/hudson/logging/LogRecorder/index.jelly b/core/src/main/resources/hudson/logging/LogRecorder/index.jelly index 4b663c90fb3d4f5e79c4a057cae2fd36e4a58834..6841b605493ab334130d0faff578ff3b48aea966 100644 --- a/core/src/main/resources/hudson/logging/LogRecorder/index.jelly +++ b/core/src/main/resources/hudson/logging/LogRecorder/index.jelly @@ -37,6 +37,10 @@ THE SOFTWARE. +
+ + + diff --git a/core/src/test/java/hudson/logging/LogRecorderTest.java b/core/src/test/java/hudson/logging/LogRecorderTest.java index 7d8e0a02f42c077c5545a117037537d7f2e951ae..2c136ae575a236ae6ad9f84083b117eeb50395c5 100644 --- a/core/src/test/java/hudson/logging/LogRecorderTest.java +++ b/core/src/test/java/hudson/logging/LogRecorderTest.java @@ -54,6 +54,21 @@ public class LogRecorderTest { assertFalse(matches("", "hudson.model.Hudson", Level.FINE)); } + @Test public void testClearing() { + LogRecorder lr = new LogRecorder("foo"); + LogRecorder.Target t = new LogRecorder.Target("", Level.FINE); + lr.targets.add(t); + + LogRecord record = createLogRecord("jenkins", Level.INFO, "message"); + lr.handler.publish(record); + assertEquals(lr.handler.getView().get(0), record); + assertTrue(lr.handler.getView().size() == 1); + + lr.handler.clear(); + + assertTrue(lr.handler.getView().size() == 0); + } + @Test public void testSpecificExclusion() { LogRecorder lr = new LogRecorder("foo");