diff --git a/all/embedded/src/main/resources/features.xml b/all/embedded/src/main/resources/features.xml index ba40860e8622..2a71d10efcd3 100644 --- a/all/embedded/src/main/resources/features.xml +++ b/all/embedded/src/main/resources/features.xml @@ -18,6 +18,7 @@ mvn:org.hibernate/hibernate-osgi/${version.hibernate.osgi} mvn:org.hibernate.javax.persistence/hibernate-jpa-2.1-api/${version.hibernate.javax.persistence} + mvn:org.apache.logging.log4j/log4j-api/2.0 mvn:org.jboss.logging/jboss-logging/${version.jboss.logging} mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.antlr/${version.hibernate_dep.antlr} mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.dom4j/${version.hibernate_dep.dom4j} diff --git a/bom/pom.xml b/bom/pom.xml index aef01e85b37f..cddfc6663ed4 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -66,12 +66,12 @@ 1.6 1.0.13 1.0.0.Final - 4.3.8.Final + 4.3.10.Final 5.3.0.Final 1.0.0 1.0-SP4 1.4.10.Final - 3.1.4.GA + 3.2.1.Final 3.6.4.Final 1.0.1.Final 4.0.25.Final diff --git a/commons/src/main/resources/features.xml b/commons/src/main/resources/features.xml index 86dc1ce87836..06babe9ff06a 100644 --- a/commons/src/main/resources/features.xml +++ b/commons/src/main/resources/features.xml @@ -4,5 +4,6 @@ mvn:org.infinispan/infinispan-commons/${project.version} mvn:org.jboss.logging/jboss-logging/${version.jboss.logging} mvn:org.jboss.marshalling/jboss-marshalling-osgi/${version.jboss.marshalling} + mvn:org.apache.logging.log4j/log4j-api/2.0 diff --git a/core/src/main/java/org/infinispan/topology/ClusterTopologyManagerImpl.java b/core/src/main/java/org/infinispan/topology/ClusterTopologyManagerImpl.java index 3155b9a76b72..71ec73ffb838 100644 --- a/core/src/main/java/org/infinispan/topology/ClusterTopologyManagerImpl.java +++ b/core/src/main/java/org/infinispan/topology/ClusterTopologyManagerImpl.java @@ -269,7 +269,7 @@ public void handleClusterView(boolean mergeView, int newViewId) { boolean becameCoordinator = !isCoordinator && transport.isCoordinator(); isCoordinator = transport.isCoordinator(); if (trace) { - log.tracef("Received new cluster view: %d, isCoordinator = %s, becameCoordinator = %s", newViewId, + log.tracef("Received new cluster view: %d, isCoordinator = %s, becameCoordinator = %s", (Object)newViewId, isCoordinator, becameCoordinator); } mustRecoverClusterStatus |= mergeView || becameCoordinator; diff --git a/core/src/test/java/org/infinispan/configuration/SampleConfigFilesCorrectnessTest.java b/core/src/test/java/org/infinispan/configuration/SampleConfigFilesCorrectnessTest.java index a704514ca4bf..0b18eb3752ef 100644 --- a/core/src/test/java/org/infinispan/configuration/SampleConfigFilesCorrectnessTest.java +++ b/core/src/test/java/org/infinispan/configuration/SampleConfigFilesCorrectnessTest.java @@ -1,9 +1,15 @@ package org.infinispan.configuration; -import org.apache.log4j.AppenderSkeleton; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; -import org.apache.log4j.spi.LoggingEvent; +import java.io.File; +import java.io.FilenameFilter; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.appender.AbstractAppender; +import org.apache.logging.log4j.core.config.Configuration; +import org.apache.logging.log4j.core.layout.PatternLayout; import org.infinispan.manager.EmbeddedCacheManager; import org.infinispan.test.AbstractInfinispanTest; import org.infinispan.test.TestingUtil; @@ -11,13 +17,10 @@ import org.infinispan.util.logging.Log; import org.infinispan.util.logging.LogFactory; import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import java.io.File; -import java.io.FilenameFilter; -import java.util.Arrays; - /** * Tests the correctness of the supplied configuration files. * @@ -29,24 +32,28 @@ public class SampleConfigFilesCorrectnessTest extends AbstractInfinispanTest { public String configRoot; private InMemoryAppender appender; - private Level oldLevel; + + @BeforeClass + public void installInMemoryAppender() { + final LoggerContext ctx = (LoggerContext) LogManager.getContext(false); + final Configuration config = ctx.getConfiguration(); + config.addAppender(new InMemoryAppender()); + } @BeforeMethod public void setUpTest() { - Logger log4jLogger = Logger.getRootLogger(); - oldLevel = log4jLogger.getLevel(); - log4jLogger.setLevel(Level.WARN); - appender = new InMemoryAppender(); - log4jLogger.addAppender(appender); + final LoggerContext ctx = (LoggerContext) LogManager.getContext(false); + final Configuration config = ctx.getConfiguration(); + appender = (InMemoryAppender) config.getAppender("InMemory"); + appender.enable(Thread.currentThread()); + ctx.updateLoggers(); configRoot = "../distribution/src/main/release/common/configs/config-samples".replace('/', File.separatorChar); } @AfterMethod public void tearDownTest() { - Logger log4jLogger = Logger.getRootLogger(); - log4jLogger.setLevel(oldLevel); - log4jLogger.removeAppender(appender); - appender.close(); + appender.disable(); + } @@ -96,7 +103,15 @@ private File getRootFolder() { return file; } - private static class InMemoryAppender extends AppenderSkeleton { + private static class InMemoryAppender extends AbstractAppender { + + /** The serialVersionUID */ + private static final long serialVersionUID = 1L; + + protected InMemoryAppender() { + super("InMemory", null, PatternLayout.createDefaultLayout()); + } + String[] TOLERABLE_WARNINGS = { "Falling back to DummyTransactionManager from Infinispan", @@ -111,41 +126,22 @@ private static class InMemoryAppender extends AppenderSkeleton { "unable to find an address other than loopback for IP version IPv4", "Partition handling doesn't work for replicated caches, it will be ignored" }; - String unknownWarning; + String unknownWarning = null; /** - * As this test runs in parallel with other tests tha also log information, we should disregard other possible + * As this test runs in parallel with other tests that also log information, we should disregard other possible * warnings from other threads and only consider warnings issues within this test class's test. * * @see #isExpectedThread() */ - private Thread loggerThread = Thread.currentThread(); + private Thread loggerThread = null; - @Override - protected void append(LoggingEvent event) { - if (event.getLevel().equals(Level.WARN) && isExpectedThread()) { - boolean skipPrinting = false; - for (String knownWarn : TOLERABLE_WARNINGS) { - if (event.getMessage().toString().indexOf(knownWarn) >= 0) - skipPrinting = true; - } - - if (!skipPrinting) { - unknownWarning = event.getMessage().toString(); - log.tracef("InMemoryAppender: %s", event.getMessage().toString()); - log.tracef("TOLERABLE_WARNINGS: %s", Arrays.toString(TOLERABLE_WARNINGS)); - } - } + public void disable() { + loggerThread = null; } - @Override - public boolean requiresLayout() { - return false; - } - - @Override - public void close() { - //do nothing + public void enable(Thread thread) { + loggerThread = thread; } public boolean isFoundUnknownWarning() { @@ -157,7 +153,22 @@ public String unknownWarning() { } public boolean isExpectedThread() { - return loggerThread.equals(Thread.currentThread()); + return loggerThread != null && loggerThread.equals(Thread.currentThread()); + } + + @Override + public void append(LogEvent event) { + if (event.getLevel().equals(Level.WARN) && isExpectedThread()) { + boolean skipPrinting = false; + for (String knownWarn : TOLERABLE_WARNINGS) { + if (event.getMessage().toString().indexOf(knownWarn) >= 0) + skipPrinting = true; + } + + if (!skipPrinting) { + unknownWarning = event.getMessage().toString(); + } + } } } } diff --git a/core/src/test/java/org/infinispan/distribution/rehash/RehashStressTest.java b/core/src/test/java/org/infinispan/distribution/rehash/RehashStressTest.java index 5534b855fc7b..22e777d34361 100644 --- a/core/src/test/java/org/infinispan/distribution/rehash/RehashStressTest.java +++ b/core/src/test/java/org/infinispan/distribution/rehash/RehashStressTest.java @@ -1,6 +1,5 @@ package org.infinispan.distribution.rehash; -import org.apache.log4j.Logger; import org.infinispan.Cache; import org.infinispan.distexec.DefaultExecutorService; import org.infinispan.distexec.DistributedCallable; @@ -9,6 +8,7 @@ import org.infinispan.manager.EmbeddedCacheManager; import org.infinispan.test.AbstractInfinispanTest; import org.infinispan.test.fwk.TestCacheManagerFactory; +import org.jboss.logging.Logger; import org.testng.annotations.AfterMethod; import org.testng.annotations.Test; diff --git a/core/src/test/java/org/infinispan/distribution/topologyaware/TopologyAwareConsistentHashFactoryTest.java b/core/src/test/java/org/infinispan/distribution/topologyaware/TopologyAwareConsistentHashFactoryTest.java index 08dadcc7475a..b124da4652cf 100644 --- a/core/src/test/java/org/infinispan/distribution/topologyaware/TopologyAwareConsistentHashFactoryTest.java +++ b/core/src/test/java/org/infinispan/distribution/topologyaware/TopologyAwareConsistentHashFactoryTest.java @@ -424,7 +424,7 @@ public void testConsistencyWhenNodeLeaves() { assertDistribution(numOwners, chMembers); for (Address addr : chMembers) { - log.debugf("Removing node %s" + addr); + log.debugf("Removing node %s", addr); List
addressCopy = new ArrayList
(chMembers); addressCopy.remove(addr); DefaultConsistentHash newCH = chf.updateMembers(ch, addressCopy, null); diff --git a/core/src/test/java/org/infinispan/interceptors/distribution/L1WriteSynchronizerTest.java b/core/src/test/java/org/infinispan/interceptors/distribution/L1WriteSynchronizerTest.java index 22e16108e21f..6cd0f9f63819 100644 --- a/core/src/test/java/org/infinispan/interceptors/distribution/L1WriteSynchronizerTest.java +++ b/core/src/test/java/org/infinispan/interceptors/distribution/L1WriteSynchronizerTest.java @@ -7,13 +7,11 @@ import org.infinispan.metadata.Metadata; import org.infinispan.statetransfer.StateTransferLock; import org.infinispan.test.AbstractInfinispanTest; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.util.concurrent.BrokenBarrierException; -import java.util.concurrent.Callable; + import java.util.concurrent.CyclicBarrier; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -176,7 +174,7 @@ public void testSpawnedThreadBlockingNullValueTimeWait() throws InterruptedExcep @Test public void testSpawnedThreadBlockingException() throws InterruptedException, ExecutionException, TimeoutException { - Throwable t = mock(Throwable.class); + Throwable t = new Exception(); Future future = fork(() -> sync.get()); @@ -200,7 +198,7 @@ public void testSpawnedThreadBlockingException() throws InterruptedException, Ex @Test public void testSpawnedThreadBlockingExceptionTimeWait() throws InterruptedException, ExecutionException, TimeoutException { - Throwable t = mock(Throwable.class); + Throwable t = new Exception(); Future future = fork(() -> sync.get(5, TimeUnit.SECONDS)); diff --git a/core/src/test/java/org/infinispan/test/AbstractInfinispanTest.java b/core/src/test/java/org/infinispan/test/AbstractInfinispanTest.java index f850634af7e8..3511f4f8f5f3 100644 --- a/core/src/test/java/org/infinispan/test/AbstractInfinispanTest.java +++ b/core/src/test/java/org/infinispan/test/AbstractInfinispanTest.java @@ -58,7 +58,7 @@ protected void killSpawnedThreads() { protected void checkThreads() { int activeTasks = defaultExecutorService.getActiveCount(); if (activeTasks != 0) { - log.errorf("There were %i active tasks found in the test executor service for class %s", activeTasks, + log.errorf("There were %d active tasks found in the test executor service for class %s", activeTasks, getClass().getSimpleName()); } } @@ -445,7 +445,7 @@ public ThreadCleaner(Thread thread) { @Override public void close() { if (ref.isAlive() && !ref.isInterrupted()) { - log.warnf("There was a thread % still alive after test completion - interrupted it", + log.warnf("There was a thread %s still alive after test completion - interrupted it", ref); ref.interrupt(); } diff --git a/core/src/test/java/org/infinispan/util/logging/log4j/CompressedFileAppender.java b/core/src/test/java/org/infinispan/util/logging/log4j/CompressedFileAppender.java index 37e00a286122..a4b7f36b9c39 100644 --- a/core/src/test/java/org/infinispan/util/logging/log4j/CompressedFileAppender.java +++ b/core/src/test/java/org/infinispan/util/logging/log4j/CompressedFileAppender.java @@ -1,57 +1,142 @@ package org.infinispan.util.logging.log4j; -import org.apache.log4j.FileAppender; -import org.apache.log4j.LogManager; +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.util.zip.GZIPOutputStream; +import org.apache.logging.log4j.core.Filter; +import org.apache.logging.log4j.core.Layout; +import org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender; +import org.apache.logging.log4j.core.appender.FileManager; +import org.apache.logging.log4j.core.config.Configuration; +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.config.plugins.PluginAttribute; +import org.apache.logging.log4j.core.config.plugins.PluginConfiguration; +import org.apache.logging.log4j.core.config.plugins.PluginElement; +import org.apache.logging.log4j.core.config.plugins.PluginFactory; +import org.apache.logging.log4j.core.layout.PatternLayout; +import org.apache.logging.log4j.core.net.Advertiser; +import org.apache.logging.log4j.core.util.Booleans; +import org.apache.logging.log4j.core.util.Integers; /** - * Appender that writes to a file and compresses the output using gzip. - * - * Based on org.apache.log4j.FileAppender + * CompressedFile Appender. */ -public class CompressedFileAppender extends FileAppender { - - GZIPOutputStream gzos; - - static { - final Thread shutdownThread = new Thread(new Runnable() { - public void run() { - // This will close all the appenders gracefully. - LogManager.shutdown(); - } - }, "Log4j shutdown thread"); - Runtime.getRuntime().addShutdownHook(shutdownThread); - } - - @Override - protected OutputStreamWriter createWriter(OutputStream os) { - try { - gzos = new GZIPOutputStream(os, bufferSize); - gzos.flush(); - return super.createWriter(gzos); - } catch (IOException e) { - throw new RuntimeException("Unable to create gzipped output stream"); - } - } - - @Override - protected void reset() { - if (gzos != null) { - closeCompressor(); - gzos = null; - } - super.reset(); - } - - private void closeCompressor() { - try { - gzos.close(); - } catch (IOException e) { - throw new RuntimeException("Unable to finish gzipped output stream"); - } - } +@Plugin(name = "CompressedFile", category = "Core", elementType = "appender", printObject = true) +public final class CompressedFileAppender extends AbstractOutputStreamAppender { + + private static final long serialVersionUID = 1L; + private static final int DEFAULT_BUFFER_SIZE = 8192; + private final String fileName; + private final Advertiser advertiser; + private Object advertisement; + + private CompressedFileAppender(final String name, final Layout layout, final Filter filter, final FileManager manager, + final String filename, final boolean ignoreExceptions, final boolean immediateFlush, + final Advertiser advertiser) { + super(name, layout, filter, ignoreExceptions, immediateFlush, manager); + if (advertiser != null) { + final Map configuration = new HashMap(layout.getContentFormat()); + configuration.putAll(manager.getContentFormat()); + configuration.put("contentType", layout.getContentType()); + configuration.put("name", name); + advertisement = advertiser.advertise(configuration); + } + this.fileName = filename; + this.advertiser = advertiser; + } + + @Override + public void stop() { + super.stop(); + if (advertiser != null) { + advertiser.unadvertise(advertisement); + } + } + + /** + * Returns the file name this appender is associated with. + * @return The File name. + */ + public String getFileName() { + return this.fileName; + } + + /** + * Create a File Appender. + * @param fileName The name and path of the file. + * @param append "True" if the file should be appended to, "false" if it should be overwritten. + * The default is "true". + * @param locking "True" if the file should be locked. The default is "false". + * @param name The name of the Appender. + * @param immediateFlush "true" if the contents should be flushed on every write, "false" otherwise. The default + * is "true". + * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise + * they are propagated to the caller. + * @param bufferedIo "true" if I/O should be buffered, "false" otherwise. The default is "true". + * @param bufferSizeStr buffer size for buffered IO (default is 8192). + * @param layout The layout to use to format the event. If no layout is provided the default PatternLayout + * will be used. + * @param filter The filter, if any, to use. + * @param advertise "true" if the appender configuration should be advertised, "false" otherwise. + * @param advertiseUri The advertised URI which can be used to retrieve the file contents. + * @param config The Configuration + * @return The FileAppender. + */ + @PluginFactory + public static CompressedFileAppender createAppender( + // @formatter:off + @PluginAttribute("fileName") final String fileName, + @PluginAttribute("append") final String append, + @PluginAttribute("locking") final String locking, + @PluginAttribute("name") final String name, + @PluginAttribute("immediateFlush") final String immediateFlush, + @PluginAttribute("ignoreExceptions") final String ignore, + @PluginAttribute("bufferedIo") final String bufferedIo, + @PluginAttribute("bufferSize") final String bufferSizeStr, + @PluginElement("Layout") Layout layout, + @PluginElement("Filter") final Filter filter, + @PluginAttribute("advertise") final String advertise, + @PluginAttribute("advertiseUri") final String advertiseUri, + @PluginConfiguration final Configuration config) { + // @formatter:on + final boolean isAppend = Booleans.parseBoolean(append, true); + final boolean isLocking = Boolean.parseBoolean(locking); + boolean isBuffered = Booleans.parseBoolean(bufferedIo, true); + final boolean isAdvertise = Boolean.parseBoolean(advertise); + if (isLocking && isBuffered) { + if (bufferedIo != null) { + LOGGER.warn("Locking and buffering are mutually exclusive. No buffering will occur for " + fileName); + } + isBuffered = false; + } + final int bufferSize = Integers.parseInt(bufferSizeStr, DEFAULT_BUFFER_SIZE); + if (!isBuffered && bufferSize > 0) { + LOGGER.warn("The bufferSize is set to {} but bufferedIO is not true: {}", bufferSize, bufferedIo); + } + final boolean isFlush = Booleans.parseBoolean(immediateFlush, true); + final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true); + + if (name == null) { + LOGGER.error("No name provided for FileAppender"); + return null; + } + + if (fileName == null) { + LOGGER.error("No filename provided for FileAppender with name " + name); + return null; + } + if (layout == null) { + layout = PatternLayout.createDefaultLayout(); + } + + final CompressedFileManager manager = CompressedFileManager.getFileManager(fileName, isAppend, isLocking, isBuffered, advertiseUri, + layout, bufferSize); + if (manager == null) { + return null; + } + + return new CompressedFileAppender(name, layout, filter, manager, fileName, ignoreExceptions, isFlush, + isAdvertise ? config.getAdvertiser() : null); + } } diff --git a/core/src/test/java/org/infinispan/util/logging/log4j/CompressedFileManager.java b/core/src/test/java/org/infinispan/util/logging/log4j/CompressedFileManager.java new file mode 100644 index 000000000000..8647eabf030a --- /dev/null +++ b/core/src/test/java/org/infinispan/util/logging/log4j/CompressedFileManager.java @@ -0,0 +1,152 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.infinispan.util.logging.log4j; + +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.Serializable; +import java.util.zip.GZIPOutputStream; + +import org.apache.logging.log4j.core.Layout; +import org.apache.logging.log4j.core.appender.FileManager; +import org.apache.logging.log4j.core.appender.ManagerFactory; + +/** + * Manages actual File I/O for the CompressedFileAppender. + */ +public class CompressedFileManager extends FileManager { + + protected CompressedFileManager(String fileName, OutputStream os, boolean append, boolean locking, String advertiseURI, Layout layout, int bufferSize) { + super(fileName, os, append, locking, advertiseURI, layout, bufferSize); + } + + private static final CompressedFileManagerFactory FACTORY = new CompressedFileManagerFactory(); + + + /** + * Returns the FileManager. + * + * @param fileName + * The name of the file to manage. + * @param append + * true if the file should be appended to, false if it should be overwritten. + * @param locking + * true if the file should be locked while writing, false otherwise. + * @param bufferedIo + * true if the contents should be buffered as they are written. + * @param advertiseUri + * the URI to use when advertising the file + * @param layout + * The layout + * @param bufferSize + * buffer size for buffered IO + * @return A FileManager for the File. + */ + public static CompressedFileManager getFileManager(final String fileName, final boolean append, boolean locking, final boolean bufferedIo, final String advertiseUri, + final Layout layout, final int bufferSize) { + + if (locking && bufferedIo) { + locking = false; + } + return (CompressedFileManager) getManager(fileName, new FactoryData(append, locking, bufferedIo, bufferSize, advertiseUri, layout), FACTORY); + } + + /** + * Factory Data. + */ + private static class FactoryData { + private final boolean append; + private final boolean locking; + private final boolean bufferedIO; + private final int bufferSize; + private final String advertiseURI; + private final Layout layout; + + /** + * Constructor. + * + * @param append + * Append status. + * @param locking + * Locking status. + * @param bufferedIO + * Buffering flag. + * @param bufferSize + * Buffer size. + * @param advertiseURI + * the URI to use when advertising the file + */ + public FactoryData(final boolean append, final boolean locking, final boolean bufferedIO, final int bufferSize, final String advertiseURI, + final Layout layout) { + this.append = append; + this.locking = locking; + this.bufferedIO = bufferedIO; + this.bufferSize = bufferSize; + this.advertiseURI = advertiseURI; + this.layout = layout; + } + } + + /** + * Factory to create a FileManager. + */ + private static class CompressedFileManagerFactory implements ManagerFactory { + + /** + * Create a FileManager. + * + * @param name + * The name of the File. + * @param data + * The FactoryData + * @return The FileManager for the File. + */ + @Override + public CompressedFileManager createManager(final String name, final FactoryData data) { + final File file = new File(name); + final File parent = file.getParentFile(); + if (null != parent && !parent.exists()) { + parent.mkdirs(); + } + + OutputStream os; + try { + os = new FileOutputStream(name, data.append); + int bufferSize = data.bufferSize; + if (name.endsWith(".gz")) { + os = new GZIPOutputStream(os, bufferSize); + os.flush(); + } else { + if (data.bufferedIO) { + os = new BufferedOutputStream(os, bufferSize); + } else { + bufferSize = -1; // signals to RollingFileManager not to use BufferedOutputStream + } + } + return new CompressedFileManager(name, os, data.append, data.locking, data.advertiseURI, data.layout, bufferSize); + } catch (final IOException ex) { + LOGGER.error("FileManager (" + name + ") " + ex); + } + return null; + } + } + +} diff --git a/core/src/test/java/org/infinispan/util/logging/log4j/ThreadNameFilter.java b/core/src/test/java/org/infinispan/util/logging/log4j/ThreadNameFilter.java index ef7b6a22bc5c..60d5f4a92d7f 100644 --- a/core/src/test/java/org/infinispan/util/logging/log4j/ThreadNameFilter.java +++ b/core/src/test/java/org/infinispan/util/logging/log4j/ThreadNameFilter.java @@ -2,9 +2,16 @@ import java.util.regex.Pattern; -import org.apache.log4j.Level; -import org.apache.log4j.spi.Filter; -import org.apache.log4j.spi.LoggingEvent; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.Marker; +import org.apache.logging.log4j.core.Filter; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.Logger; +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.config.plugins.PluginAttribute; +import org.apache.logging.log4j.core.config.plugins.PluginFactory; +import org.apache.logging.log4j.core.filter.AbstractFilter; +import org.apache.logging.log4j.message.Message; /** * Log4j {@link Filter} that only allow events from threads matching a regular expression. @@ -13,34 +20,69 @@ * @author Dan Berindei * @since 5.2 */ -public class ThreadNameFilter extends Filter { - private Level threshold = Level.DEBUG; - private Pattern includePattern; +@Plugin(name = "ThreadNameFilter", category = "Core", elementType = Filter.ELEMENT_TYPE, printObject = true) +public final class ThreadNameFilter extends AbstractFilter { + /** The serialVersionUID */ + private static final long serialVersionUID = 1L; + private final Level level; + private final Pattern includePattern; - public Level getThreshold() { - return threshold; + public ThreadNameFilter(Level actualLevel, String includeRegex) { + this.level = actualLevel; + this.includePattern = Pattern.compile(includeRegex); } - public void setThreshold(Level threshold) { - this.threshold = threshold; + @Override + public Result filter(final Logger logger, final Level level, final Marker marker, final String msg, + final Object... params) { + return filter(level, Thread.currentThread().getName()); } - public String getInclude() { - return includePattern != null ? includePattern.pattern() : null; + @Override + public Result filter(final Logger logger, final Level level, final Marker marker, final Object msg, + final Throwable t) { + return filter(level, Thread.currentThread().getName()); } - public void setInclude(String include) { - this.includePattern = Pattern.compile(include); + @Override + public Result filter(final Logger logger, final Level level, final Marker marker, final Message msg, + final Throwable t) { + return filter(level, Thread.currentThread().getName()); } @Override - public int decide(LoggingEvent event) { - if (event.getLevel().isGreaterOrEqual(threshold)) { - return Filter.NEUTRAL; - } else if (includePattern == null || includePattern.matcher(event.getThreadName()).find()) { - return Filter.NEUTRAL; + public Result filter(final LogEvent event) { + return filter(event.getLevel(), event.getThreadName()); + } + + private Result filter(final Level level, String threadName) { + if (level.isMoreSpecificThan(this.level)) { + return Result.NEUTRAL; + } else if (includePattern == null || includePattern.matcher(threadName).find()) { + return Result.NEUTRAL; } else { - return Filter.DENY; + return Result.DENY; } } + + @Override + public String toString() { + return level.toString(); + } + + /** + * Create a ThresholdFilter. + * @param level The log Level. + * @param match The action to take on a match. + * @param mismatch The action to take on a mismatch. + * @return The created ThresholdFilter. + */ + @PluginFactory + public static ThreadNameFilter createFilter( + @PluginAttribute("level") final Level level, + @PluginAttribute("include") final String include) { + final Level actualLevel = level == null ? Level.DEBUG : level; + final String includeRegex = include == null ? ".*" : include; + return new ThreadNameFilter(actualLevel, includeRegex); + } } diff --git a/core/src/test/resources/log4j-trace.xml b/core/src/test/resources/log4j-trace.xml deleted file mode 100644 index 6cbd24e1381b..000000000000 --- a/core/src/test/resources/log4j-trace.xml +++ /dev/null @@ -1,75 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/core/src/test/resources/log4j.xml b/core/src/test/resources/log4j.xml deleted file mode 100644 index 59692072581b..000000000000 --- a/core/src/test/resources/log4j.xml +++ /dev/null @@ -1,93 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/core/src/test/resources/log4j2-trace.xml b/core/src/test/resources/log4j2-trace.xml new file mode 100644 index 000000000000..7bc256bc3f7a --- /dev/null +++ b/core/src/test/resources/log4j2-trace.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/src/test/resources/log4j2.xml b/core/src/test/resources/log4j2.xml new file mode 100644 index 000000000000..93b014e7a336 --- /dev/null +++ b/core/src/test/resources/log4j2.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demos/gridfs-webdav/pom.xml b/demos/gridfs-webdav/pom.xml index 99d73e8dd9bf..0f305bebe7ea 100644 --- a/demos/gridfs-webdav/pom.xml +++ b/demos/gridfs-webdav/pom.xml @@ -28,8 +28,8 @@ provided - log4j - log4j + org.apache.logging.log4j + log4j-core - \ No newline at end of file + diff --git a/demos/nearcache/pom.xml b/demos/nearcache/pom.xml index 6d8503915866..25a79b8aa29d 100644 --- a/demos/nearcache/pom.xml +++ b/demos/nearcache/pom.xml @@ -74,10 +74,10 @@ - log4j - log4j + org.apache.logging.log4j + log4j-core - \ No newline at end of file + diff --git a/integrationtests/osgi/pom.xml b/integrationtests/osgi/pom.xml index 7ab3e22e334e..34d372dac6f0 100644 --- a/integrationtests/osgi/pom.xml +++ b/integrationtests/osgi/pom.xml @@ -24,6 +24,11 @@ + + org.apache.logging.log4j + log4j-slf4j-impl + test + org.infinispan infinispan-commons @@ -267,4 +272,4 @@ - \ No newline at end of file + diff --git a/integrationtests/security-it/pom.xml b/integrationtests/security-it/pom.xml index c18c6070750d..8ccaa9f876e7 100755 --- a/integrationtests/security-it/pom.xml +++ b/integrationtests/security-it/pom.xml @@ -25,8 +25,8 @@ test - org.slf4j - slf4j-log4j12 + org.apache.logging.log4j + log4j-slf4j-impl test @@ -43,6 +43,12 @@ org.picketbox jbosssx-bare test + + + hibernate-annotations + org.hibernate + + diff --git a/parent/pom.xml b/parent/pom.xml index 506ccfbb98da..a131bf1d0e0f 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -117,8 +117,7 @@ 3.1.1 1.4.180 1.3.173 - 3.5.6-Final - 4.3.6.Final + 4.3.10.Final ${version.hibernate.core} 1.3.0.Alpha1 ${version.hibernate.core} @@ -149,7 +148,7 @@ 4.11 0.7 1.7 - 1.2.16 + 2.3 4.10.4 1.2.6 1.9.5 @@ -187,8 +186,8 @@ 0.5.10.201208310627 3.3.1 2.2.0 - 2.4.1 - 4.2.0 + 3.0.4 + 4.5.0 Infinispan JaCoCo Report ../ ../jacoco-html @@ -432,8 +431,13 @@ ${version.jgoodies.forms} - log4j - log4j + org.apache.logging.log4j + log4j-core + ${version.log4j} + + + org.apache.logging.log4j + log4j-slf4j-impl ${version.log4j} @@ -506,11 +510,6 @@ jackson-mapper-asl ${version.jackson} - - org.hibernate - hibernate-annotations - ${version.hibernate.annotations} - org.hibernate hibernate-core @@ -1040,8 +1039,8 @@ test - log4j - log4j + org.apache.logging.log4j + log4j-core true @@ -1858,7 +1857,7 @@ maven-surefire-plugin - log4j-trace.xml + log4j2-trace.xml diff --git a/persistence/jpa/src/main/resources/features.xml b/persistence/jpa/src/main/resources/features.xml index c8cbf2a2e16c..2e47834c5bf6 100644 --- a/persistence/jpa/src/main/resources/features.xml +++ b/persistence/jpa/src/main/resources/features.xml @@ -22,6 +22,7 @@ mvn:org.hibernate.javax.persistence/hibernate-jpa-2.1-api/${version.hibernate.javax.persistence} + mvn:org.apache.logging.log4j/log4j-api/2.0 mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.antlr/${version.hibernate_dep.antlr} mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.dom4j/${version.hibernate_dep.dom4j} mvn:com.fasterxml/classmate/${version.hibernate_dep.classmate} diff --git a/spring/spring/pom.xml b/spring/spring/pom.xml index a69134776a9c..808d8922363b 100644 --- a/spring/spring/pom.xml +++ b/spring/spring/pom.xml @@ -123,8 +123,8 @@ runtime - log4j - log4j + org.apache.logging.log4j + log4j-core runtime true @@ -225,4 +225,4 @@ - \ No newline at end of file + diff --git a/spring/spring4/pom.xml b/spring/spring4/pom.xml index cc11fbd37db6..841d819e99b1 100644 --- a/spring/spring4/pom.xml +++ b/spring/spring4/pom.xml @@ -128,8 +128,8 @@ runtime - log4j - log4j + org.apache.logging.log4j + log4j-core runtime true @@ -240,4 +240,4 @@ - \ No newline at end of file +