diff --git a/common/source/java/ch/systemsx/cisd/common/logging/BufferedAppender.java b/common/source/java/ch/systemsx/cisd/common/logging/BufferedAppender.java index 599b8807b6563421a93312c17f588acc574deb4d..2e1f4a5fe273e9877b46c2094764c4007917a071 100644 --- a/common/source/java/ch/systemsx/cisd/common/logging/BufferedAppender.java +++ b/common/source/java/ch/systemsx/cisd/common/logging/BufferedAppender.java @@ -23,6 +23,8 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.apache.log4j.PatternLayout; import org.apache.log4j.WriterAppender; +import org.apache.log4j.spi.Filter; +import org.apache.log4j.spi.LoggingEvent; /** * A <code>WriterAppender</code> extension that buffers its output in a @@ -61,10 +63,33 @@ public final class BufferedAppender extends WriterAppender public BufferedAppender(final String pattern, final Level logLevel) { - super(); + this(pattern, logLevel, null); + } + + /** + * Creates an instance for specified optional pattern, log level and optional class onto which + * log entries are filtered. + */ + public BufferedAppender(final String patternOrNull, final Level logLevel, + final Class<?> classToFilterOnOrNull) + { logRecorder = new ByteArrayOutputStream(); + if (classToFilterOnOrNull != null) + { + this.addFilter(new Filter() + { + String className = classToFilterOnOrNull.getSimpleName(); + + @Override + public int decide(LoggingEvent event) + { + return event.getLoggerName().endsWith(className) ? Filter.ACCEPT + : Filter.NEUTRAL; + } + }); + } setWriter(createWriter(logRecorder)); - setLayout(createLayout(pattern)); + setLayout(createLayout(patternOrNull)); configureRootLogger(); setThreshold(logLevel); } diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/ShareIdManagerTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/ShareIdManagerTest.java index 1f3d19ae3d9d6f283d3df2f162f40d5fa2051e8c..090c70265ec08ba77f33bc5471ecf2c4836b3f66 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/ShareIdManagerTest.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/dss/generic/server/ShareIdManagerTest.java @@ -58,7 +58,7 @@ public class ShareIdManagerTest extends AssertJUnit { level = Logger.getRootLogger().getLevel(); Logger.getRootLogger().setLevel(Level.DEBUG); - logRecorder = new BufferedAppender("%-5p %c - %m%n", Level.DEBUG); + logRecorder = new BufferedAppender("%-5p %c - %m%n", Level.DEBUG, ShareIdManager.class); context = new Mockery(); service = context.mock(IEncapsulatedOpenBISService.class); context.checking(new Expectations()