[AMQ-8520] WIP: Convert activemq-unit-tests to log4j2

This commit is contained in:
Matt Pavlovich 2022-03-02 09:13:55 -06:00
parent c1b35058d3
commit 7ec5254bb5
54 changed files with 883 additions and 620 deletions

View File

@ -34,7 +34,6 @@ import javax.jms.TextMessage;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TransportConnector;
import org.apache.activemq.broker.region.Queue;
import org.apache.activemq.broker.region.Topic;
import org.apache.activemq.broker.region.policy.PolicyEntry;
import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.broker.region.policy.VMPendingQueueMessageStoragePolicy;
@ -42,9 +41,10 @@ import org.apache.activemq.broker.region.policy.VMPendingSubscriberMessageStorag
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.transport.tcp.TcpTransport;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Appender;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.LogEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -261,22 +261,24 @@ public class ProducerFlowControlTest extends JmsTestSupport {
Appender appender = new DefaultTestAppender() {
@Override
public void doAppend(LoggingEvent event) {
if (event.getLevel().equals(Level.WARN) && event.getMessage().toString().contains("Usage Manager Memory Limit")) {
public void append(LogEvent event) {
if (event.getLevel().equals(Level.WARN) && event.getMessage().getFormattedMessage().contains("Usage Manager Memory Limit")) {
LOG.info("received warn log message: " + event.getMessage());
warnings.incrementAndGet();
}
if (event.getLevel().equals(Level.DEBUG) && event.getMessage().toString().contains("Usage Manager Memory Limit")) {
if (event.getLevel().equals(Level.DEBUG) && event.getMessage().getFormattedMessage().contains("Usage Manager Memory Limit")) {
LOG.info("received debug log message: " + event.getMessage());
debugs.incrementAndGet();
}
}
};
org.apache.log4j.Logger log4jLogger =
org.apache.log4j.Logger.getLogger(Queue.class);
appender.start();
org.apache.logging.log4j.core.Logger log4jLogger = (org.apache.logging.log4j.core.Logger)LogManager.getLogger(Queue.class);
log4jLogger.addAppender(appender);
log4jLogger.setLevel(Level.DEBUG);
try {
ConnectionFactory factory = createConnectionFactory();
connection = (ActiveMQConnection)factory.createConnection();

View File

@ -24,9 +24,13 @@ import javax.jms.JMSException;
import javax.jms.Session;
import junit.framework.Test;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Appender;
import org.apache.log4j.spi.LoggingEvent;
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.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -48,20 +52,22 @@ public class ReconnectWithSameClientIDTest extends EmbeddedBrokerTestSupport {
public void testReconnectMultipleTimesWithSameClientID() throws Exception {
org.apache.log4j.Logger log4jLogger =
org.apache.log4j.Logger.getLogger(org.apache.activemq.broker.jmx.ManagedTransportConnection.class);
final AtomicBoolean failed = new AtomicBoolean(false);
Appender appender = new DefaultTestAppender() {
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger((org.apache.activemq.broker.jmx.ManagedTransportConnection.class)));
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
if (event.getMessage().toString().startsWith("Failed to register MBean")) {
public void append(LogEvent event) {
if (event.getMessage().getFormattedMessage().startsWith("Failed to register MBean")) {
LOG.info("received unexpected log message: " + event.getMessage());
failed.set(true);
}
}
};
log4jLogger.addAppender(appender);
appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
try {
connection = connectionFactory.createConnection();
useConnection(connection);
@ -85,7 +91,7 @@ public class ReconnectWithSameClientIDTest extends EmbeddedBrokerTestSupport {
connection = connectionFactory.createConnection();
useConnection(connection);
} finally {
log4jLogger.removeAppender(appender);
logger.removeAppender(appender);
}
assertFalse("failed on unexpected log event", failed.get());
}

View File

@ -18,39 +18,44 @@
package org.apache.activemq;
import org.apache.activemq.broker.jmx.ManagementContext;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.activemq.util.Wait;
import org.apache.log4j.Appender;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.*;
import static org.junit.Assert.assertFalse;
import java.util.concurrent.*;
import org.apache.activemq.broker.BrokerService;
import javax.management.JMException;
import javax.management.ObjectName;
public class TcpTransportCloseConnectionTest {
static boolean transportConnectionFailed = false;
static final org.apache.logging.log4j.core.Appender appender;
private BrokerService broker;
private final String uri = "tcp://localhost:0?wireFormat.maxInactivityDuration=500";
static final Appender appender = new DefaultTestAppender() {
@Override
public void doAppend(LoggingEvent event) {
if(event.getMessage().toString().contains("Transport Connection")
&& event.getMessage().toString().contains("failed")
&& (event.getMessage().toString().contains("java.net.SocketException") || event.getMessage().toString().contains("java.io.EOFException"))) {
transportConnectionFailed = true;
static {
appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void append(LogEvent event) {
String message = event.getMessage().getFormattedMessage();
if(message.contains("Transport Connection")
&& message.contains("failed")
&& (message.contains("java.net.SocketException") || message.contains("java.io.EOFException"))) {
transportConnectionFailed = true;
}
}
}
};
};
appender.start();
}
class CustomManagementContext extends ManagementContext {
@Override
@ -67,12 +72,12 @@ public class TcpTransportCloseConnectionTest {
@BeforeClass
public static void setUp() throws Exception {
org.apache.log4j.Logger.getRootLogger().addAppender(appender);
org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger()).addAppender(appender);
}
@AfterClass
public static void setDown() throws Exception {
org.apache.log4j.Logger.getRootLogger().removeAppender(appender);
org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger()).removeAppender(appender);
}
@Before

View File

@ -27,8 +27,9 @@ import javax.management.ObjectName;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.EmbeddedBrokerTestSupport;
import org.apache.activemq.broker.BrokerService;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Logger;
import org.junit.Test;
import org.slf4j.LoggerFactory;
@ -112,7 +113,7 @@ public class Log4JConfigTest extends EmbeddedBrokerTestSupport {
String level = log4jConfigView.getLogLevel("not.a.logger");
assertNotNull(level);
assertFalse(level.isEmpty());
assertEquals(Logger.getRootLogger().getLevel().toString(), level);
assertEquals(LogManager.getRootLogger().getLevel().toString(), level);
}
@Test
@ -166,7 +167,7 @@ public class Log4JConfigTest extends EmbeddedBrokerTestSupport {
assertNotNull(level);
assertFalse(level.isEmpty());
String currentRootLevel = Logger.getRootLogger().getLevel().toString();
String currentRootLevel = LogManager.getRootLogger().getLevel().toString();
assertEquals(currentRootLevel, level);
}
@ -177,12 +178,12 @@ public class Log4JConfigTest extends EmbeddedBrokerTestSupport {
Log4JConfigViewMBean log4jConfigView = MBeanServerInvocationHandler.newProxyInstance(
mbeanServer, log4jConfigViewName, Log4JConfigViewMBean.class, true);
String currentRootLevel = Logger.getRootLogger().getLevel().toString();
String currentRootLevel = LogManager.getRootLogger().getLevel().toString();
log4jConfigView.setRootLogLevel("WARN");
currentRootLevel = Logger.getRootLogger().getLevel().toString();
currentRootLevel = LogManager.getRootLogger().getLevel().toString();
assertEquals("WARN", currentRootLevel);
log4jConfigView.setRootLogLevel("INFO");
currentRootLevel = Logger.getRootLogger().getLevel().toString();
currentRootLevel = LogManager.getRootLogger().getLevel().toString();
assertEquals("INFO", currentRootLevel);
Level level;

View File

@ -24,9 +24,13 @@ import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.command.ActiveMQTopic;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.activemq.util.Wait;
import org.apache.log4j.Appender;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;
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.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -90,20 +94,22 @@ public class DestinationGCStressTest {
@Test(timeout = 60000)
public void testClashWithPublishAndGC() throws Exception {
org.apache.log4j.Logger log4jLogger =
org.apache.log4j.Logger.getLogger(RegionBroker.class);
final AtomicBoolean failed = new AtomicBoolean(false);
Appender appender = new DefaultTestAppender() {
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(RegionBroker.class));
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
if (event.getLevel().equals(Level.ERROR) && event.getMessage().toString().startsWith("Failed to remove inactive")) {
public void append(LogEvent event) {
if (event.getLevel().equals(Level.ERROR) && event.getMessage().getFormattedMessage().startsWith("Failed to remove inactive")) {
logger.info("received unexpected log message: " + event.getMessage());
failed.set(true);
}
}
};
log4jLogger.addAppender(appender);
appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
try {
final AtomicInteger max = new AtomicInteger(20000);
@ -147,7 +153,7 @@ public class DestinationGCStressTest {
connection.close();
} finally {
log4jLogger.removeAppender(appender);
logger.removeAppender(appender);
}
assertFalse("failed on unexpected log event", failed.get());
@ -156,16 +162,14 @@ public class DestinationGCStressTest {
@Test(timeout = 60000)
public void testAddRemoveWildcardWithGc() throws Exception {
org.apache.log4j.Logger log4jLogger =
org.apache.log4j.Logger.getLogger(RegionBroker.class);
final AtomicBoolean failed = new AtomicBoolean(false);
Appender appender = new DefaultTestAppender() {
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(RegionBroker.class));
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
if (event.getLevel().equals(Level.ERROR) && event.getMessage().toString().startsWith("Failed to remove inactive")) {
if (event.getThrowableInformation().getThrowable() != null
&& event.getThrowableInformation().getThrowable().getCause() instanceof BrokerStoppedException) {
public void append(LogEvent event) {
if (event.getLevel().equals(Level.ERROR) && event.getMessage().getFormattedMessage().startsWith("Failed to remove inactive")) {
if (event.getThrown() != null
&& event.getThrown().getCause() instanceof BrokerStoppedException) {
// ok
} else {
logger.info("received unexpected log message: " + event.getMessage());
@ -174,7 +178,11 @@ public class DestinationGCStressTest {
}
}
};
log4jLogger.addAppender(appender);
appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
try {
final AtomicInteger max = new AtomicInteger(10000);
@ -241,7 +249,7 @@ public class DestinationGCStressTest {
connection.close();
} finally {
log4jLogger.removeAppender(appender);
logger.removeAppender(appender);
}
assertFalse("failed on unexpected log event", failed.get());

View File

@ -43,9 +43,9 @@ import org.apache.activemq.broker.region.policy.PolicyEntry;
import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Appender;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LogEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -108,14 +108,15 @@ public class QueuePurgeTest extends CombinationTestSupport {
QueueViewMBean proxy = getProxyToQueueViewMBean();
LOG.info("purging..");
org.apache.log4j.Logger log4jLogger = org.apache.log4j.Logger.getLogger(org.apache.activemq.broker.jmx.QueueView.class);
org.apache.logging.log4j.core.Logger log4jLogger = (org.apache.logging.log4j.core.Logger)LogManager.getLogger(org.apache.activemq.broker.jmx.QueueView.class);
final AtomicBoolean gotPurgeLogMessage = new AtomicBoolean(false);
Appender appender = new DefaultTestAppender() {
@Override
public void doAppend(LoggingEvent event) {
if (event.getMessage() instanceof String) {
String message = (String) event.getMessage();
public void append(LogEvent event) {
if (event.getMessage() != null) {
String message = event.getMessage().getFormattedMessage();
if (message.contains("purge of " + NUM_TO_SEND +" messages")) {
LOG.info("Received a log message: {} ", event.getMessage());
gotPurgeLogMessage.set(true);
@ -123,16 +124,14 @@ public class QueuePurgeTest extends CombinationTestSupport {
}
}
};
Level level = log4jLogger.getLevel();
log4jLogger.setLevel(Level.INFO);
appender.start();
log4jLogger.addAppender(appender);
try {
proxy.purge();
} finally {
log4jLogger.setLevel(level);
log4jLogger.removeAppender(appender);
}

View File

@ -40,9 +40,10 @@ import org.apache.activemq.store.kahadb.scheduler.JobSchedulerStoreImpl;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.activemq.util.ProducerThread;
import org.apache.activemq.util.Wait;
import org.apache.log4j.Appender;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.LogEvent;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -224,8 +225,8 @@ public class JmsSchedulerTest extends JobSchedulerTestSupport {
Appender appender = new DefaultTestAppender() {
@Override
public void doAppend(LoggingEvent event) {
if (event.getMessage().toString().contains("Removed Job past last appened in the journal")) {
public void append(LogEvent event) {
if (event.getMessage() != null && event.getMessage().getFormattedMessage().contains("Removed Job past last appened in the journal")) {
numberOfDiscardedJobs.incrementAndGet();
}
}
@ -263,8 +264,7 @@ public class JmsSchedulerTest extends JobSchedulerTestSupport {
}
private void registerLogAppender(final Appender appender) {
org.apache.log4j.Logger log4jLogger =
org.apache.log4j.Logger.getLogger(JobSchedulerStoreImpl.class);
org.apache.logging.log4j.core.Logger log4jLogger = (org.apache.logging.log4j.core.Logger)LogManager.getLogger(JobSchedulerStoreImpl.class);
log4jLogger.addAppender(appender);
log4jLogger.setLevel(Level.TRACE);
}

View File

@ -32,7 +32,6 @@ import org.apache.activemq.command.ActiveMQMessage;
import org.apache.activemq.store.kahadb.disk.journal.DataFile;
import org.apache.activemq.store.kahadb.disk.page.Transaction;
import org.apache.activemq.store.kahadb.scheduler.JobSchedulerStoreImpl;
import org.apache.log4j.Level;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -49,6 +48,8 @@ import javax.jms.TextMessage;
import org.apache.activemq.ScheduledMessage;
import org.apache.activemq.command.ActiveMQMessage;
import org.apache.activemq.util.IdGenerator;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -69,7 +70,7 @@ public class JobSchedulerManagementTest extends JobSchedulerTestSupport {
@Test
public void testRemoveAllScheduled() throws Exception {
org.apache.log4j.Logger.getLogger(Transaction.class).setLevel(Level.DEBUG);
org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(Transaction.class)).setLevel(Level.DEBUG);
final int COUNT = 5000;
System.setProperty("maxKahaDBTxSize", "" + (500*1024));
Connection connection = createConnection();

View File

@ -52,7 +52,8 @@ import org.apache.activemq.store.kahadb.scheduler.JobSchedulerStoreImpl;
import org.apache.activemq.util.ByteSequence;
import org.apache.activemq.util.IOHelper;
import org.apache.activemq.util.Wait;
import org.apache.log4j.Level;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -76,7 +77,7 @@ public class JobSchedulerRedliveryPluginDLQStoreCleanupTest {
public void setUp() throws Exception {
// investigate gc issue - store usage not getting released
org.apache.log4j.Logger.getLogger(JobSchedulerStoreImpl.class).setLevel(Level.TRACE);
org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(JobSchedulerStoreImpl.class)).setLevel(Level.TRACE);
File directory = new File("target/test/ScheduledJobsDB");
IOHelper.mkdirs(directory);

View File

@ -29,7 +29,8 @@ import org.apache.activemq.store.kahadb.scheduler.JobSchedulerStoreImpl;
import org.apache.activemq.util.ByteSequence;
import org.apache.activemq.util.IOHelper;
import org.apache.activemq.util.Wait;
import org.apache.log4j.Level;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -48,7 +49,7 @@ public class JobSchedulerStoreCheckpointTest {
public void setUp() throws Exception {
// investigate gc issue - store usage not getting released
org.apache.log4j.Logger.getLogger(JobSchedulerStoreImpl.class).setLevel(Level.TRACE);
org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(JobSchedulerStoreImpl.class)).setLevel(Level.TRACE);
File directory = new File("target/test/ScheduledJobsDB");
IOHelper.mkdirs(directory);

View File

@ -36,7 +36,6 @@ import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.ScheduledMessage;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.util.IOHelper;
import org.apache.log4j.BasicConfigurator;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -74,7 +73,9 @@ public class LostScheduledMessagesTest {
@After
public void tearDown() throws Exception {
broker.stop();
BasicConfigurator.resetConfiguration();
// [AMQ-8520] FIXME: Convert or remove if not needed
//BasicConfigurator.resetConfiguration();
}
@Test

View File

@ -43,14 +43,15 @@ import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.AutoFailTestSupport;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.util.Wait;
import org.apache.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A AMQ1936Test
*
*/
public class AMQ1936Test extends TestCase {
private final static Logger logger = Logger.getLogger(AMQ1936Test.class);
private final static Logger logger = LoggerFactory.getLogger(AMQ1936Test.class);
private final static String TEST_QUEUE_NAME = "dynamicQueues/duplicate.message.test.queue";
// //--
//
@ -177,7 +178,7 @@ public class AMQ1936Test extends TestCase {
}
if (messages.containsKey(message.getJMSMessageID())) {
duplicateSignal.countDown();
logger.fatal("duplicate message id detected:" + message.getJMSMessageID());
logger.error("duplicate message id detected:" + message.getJMSMessageID());
fail("Duplicate message id detected:" + message.getJMSMessageID());
} else {
messages.put(message.getJMSMessageID(), message.getJMSMessageID());
@ -275,14 +276,14 @@ public class AMQ1936Test extends TestCase {
try {
receiver.close();
} catch (JMSException e) {
logger.warn(e);
logger.warn(e.getMessage(), e);
}
}
if (session != null) {
try {
session.close();
} catch (JMSException e) {
logger.warn(e);
logger.warn(e.getMessage(), e);
}
}
if (queueConnection != null) {
@ -290,12 +291,12 @@ public class AMQ1936Test extends TestCase {
}
}
} catch (JMSException e) {
logger.error(e);
logger.error(e.getMessage(), e);
e.printStackTrace();
} catch (NamingException e) {
logger.error(e);
logger.error(e.getMessage(), e);
} catch (Exception e) {
logger.error(e);
logger.error(e.getMessage(), e);
e.printStackTrace();
}
}

View File

@ -28,10 +28,10 @@ import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.TransportConnection;
import org.apache.activemq.transport.TransportDisposedIOException;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Appender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.LogEvent;
import org.slf4j.LoggerFactory;
public class AMQ2902Test extends TestCase {
@ -41,10 +41,11 @@ public class AMQ2902Test extends TestCase {
final AtomicBoolean failedToFindMDC = new AtomicBoolean(Boolean.FALSE);
Appender appender = new DefaultTestAppender() {
@SuppressWarnings("deprecation")
@Override
public void doAppend(LoggingEvent event) {
if (event.getThrowableInformation() != null
&& event.getThrowableInformation().getThrowable() instanceof TransportDisposedIOException) {
public void append(LogEvent event) {
if (event.getThrown() != null
&& event.getThrown() instanceof TransportDisposedIOException) {
// Prevent StackOverflowException so we can see a sane stack trace.
if (gotExceptionInLog.get()) {
@ -52,11 +53,11 @@ public class AMQ2902Test extends TestCase {
}
gotExceptionInLog.set(Boolean.TRUE);
LOG.error("got event: " + event + ", ex:" + event.getThrowableInformation().getThrowable(), event.getThrowableInformation().getThrowable());
LOG.error("got event: " + event + ", ex:" + event.getThrown(), event);
LOG.error("Event source: ", new Throwable("Here"));
}
if( !((String) event.getMessage()).startsWith("Loaded the Bouncy Castle security provider at position") ) {
if (event.getMDC("activemq.broker") == null) {
if( !((String) event.getMessage().getFormattedMessage()).startsWith("Loaded the Bouncy Castle security provider at position") ) {
if (event.getContextData().getValue("activemq.broker") == null) {
failedToFindMDC.set(Boolean.TRUE);
}
}
@ -84,14 +85,14 @@ public class AMQ2902Test extends TestCase {
public void setUp() throws Exception {
gotExceptionInLog.set(Boolean.FALSE);
failedToFindMDC.set(Boolean.FALSE);
Logger.getRootLogger().addAppender(appender);
Logger.getLogger(TransportConnection.class.getName() + ".Transport").setLevel(Level.DEBUG);
Logger.getLogger(TransportConnection.class.getName()).setLevel(Level.DEBUG);
((org.apache.logging.log4j.core.Logger)LogManager.getRootLogger()).addAppender(appender);
((org.apache.logging.log4j.core.Logger)LogManager.getLogger(TransportConnection.class.getName() + ".Transport")).setLevel(Level.DEBUG);
((org.apache.logging.log4j.core.Logger)LogManager.getLogger(TransportConnection.class)).setLevel(Level.DEBUG);
}
@Override
public void tearDown() throws Exception {
Logger.getRootLogger().removeAppender(appender);
((org.apache.logging.log4j.core.Logger)LogManager.getRootLogger()).removeAppender(appender);
assertFalse("got unexpected ex in log on graceful close", gotExceptionInLog.get());
assertFalse("MDC is there", failedToFindMDC.get());
}

View File

@ -32,10 +32,15 @@ import javax.jms.Session;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.region.cursors.AbstractStoreCursor;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Appender;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;
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.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
@ -71,15 +76,15 @@ public class AMQ3567Test {
@Test
public void runTest() throws Exception {
produceSingleMessage();
org.apache.log4j.Logger log4jLogger = org.apache.log4j.Logger.getLogger("org.apache.activemq.util.ServiceSupport");
final AtomicBoolean failed = new AtomicBoolean(false);
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger("org.apache.activemq.util.ServiceSupport"));
Appender appender = new DefaultTestAppender() {
final AtomicBoolean failed = new AtomicBoolean(false);
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
if (event.getThrowableInformation() != null) {
if (event.getThrowableInformation().getThrowable() instanceof InterruptedException) {
InterruptedException ie = (InterruptedException)event.getThrowableInformation().getThrowable();
public void append(LogEvent event) {
if (event.getThrown() != null) {
if (event.getThrown() instanceof InterruptedException) {
InterruptedException ie = (InterruptedException)event.getThrown();
if (ie.getMessage().startsWith("Could not stop service:")) {
logger.info("Received an interrupted exception : ", ie);
failed.set(true);
@ -88,10 +93,13 @@ public class AMQ3567Test {
}
}
};
log4jLogger.addAppender(appender);
appender.start();
Level level = log4jLogger.getLevel();
log4jLogger.setLevel(Level.DEBUG);
Level level = logger.getLevel();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
logger.setLevel(Level.DEBUG);
try {
stopConsumer();
@ -101,8 +109,8 @@ public class AMQ3567Test {
}
} finally {
log4jLogger.setLevel(level);
log4jLogger.removeAppender(appender);
logger.setLevel(level);
logger.removeAppender(appender);
}
}

View File

@ -30,35 +30,47 @@ import org.apache.activemq.broker.region.policy.PolicyEntry;
import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.transport.stomp.Stomp;
import org.apache.activemq.transport.stomp.StompConnection;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Appender;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class AMQ3622Test {
protected static final Appender appender;
protected static final AtomicBoolean failed = new AtomicBoolean(false);
protected BrokerService broker;
protected AtomicBoolean failed = new AtomicBoolean(false);
protected String connectionUri;
protected Appender appender = new DefaultTestAppender() {
protected Logger logger;
static {
appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
public void append(LogEvent event) {
System.err.println(event.getMessage());
if (event.getThrowableInformation() != null) {
if (event.getThrowableInformation().getThrowable() instanceof NullPointerException) {
if (event.getThrown() != null) {
if (event.getThrown() instanceof NullPointerException) {
failed.set(true);
}
}
}
};
}
};
appender.start();
}
@Before
public void before() throws Exception {
Logger.getRootLogger().addAppender(appender);
logger = Logger.class.cast(LogManager.getRootLogger());
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
broker = new BrokerService();
broker.setDataDirectory("target" + File.separator + "activemq-data");
@ -88,7 +100,7 @@ public class AMQ3622Test {
public void after() throws Exception {
broker.stop();
broker.waitUntilStopped();
Logger.getRootLogger().removeAppender(appender);
logger.removeAppender(appender);
}
@Test

View File

@ -18,10 +18,13 @@ package org.apache.activemq.bugs;
import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Appender;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggingEvent;
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.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -80,18 +83,23 @@ public class AMQ3625Test {
@Test
public void go() throws Exception {
Appender appender = new DefaultTestAppender() {
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
if (event.getMessage().toString().contains("java.lang.SecurityException")) {
public void append(LogEvent event) {
if (event.getMessage() != null && event.getMessage().getFormattedMessage().contains("java.lang.SecurityException")) {
authenticationFailed.set(true);
}
if (event.getMessage().toString().contains("NullPointerException")) {
if (event.getMessage() != null && event.getMessage().getFormattedMessage().contains("NullPointerException")) {
gotNPE.set(true);
}
}
};
Logger.getRootLogger().addAppender(appender);
appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
String connectURI = broker1.getConnectorByName("openwire").getConnectUri().toString();
connectURI = connectURI.replace("?needClientAuth=true", "?verifyHostName=false");
@ -99,7 +107,7 @@ public class AMQ3625Test {
Thread.sleep(10 * 1000);
Logger.getRootLogger().removeAppender(appender);
logger.removeAppender(appender);
assertTrue(authenticationFailed.get());
assertFalse(gotNPE.get());

View File

@ -26,10 +26,15 @@ import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.util.LoggingBrokerPlugin;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Appender;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -38,8 +43,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class AMQ3779Test {
private static final Logger LOG = Logger.getLogger(AMQ3779Test.class);
private static final Logger LOG = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(AMQ3779Test.class));
private static final String qName = "QNameToFind";
private BrokerService brokerService;
@ -51,20 +55,28 @@ public class AMQ3779Test {
public void setUp() throws Exception {
ok.set(false);
appender = new DefaultTestAppender() {
final var rootLogger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
public void append(LogEvent event) {
if (event.getLoggerName().toString().contains(qName)) {
ok.set(true);
}
if (event.getMessage().toString().contains("Sending") && event.getMessage().toString().contains("size = 0")) {
String msg = event.getMessage().getFormattedMessage();
if (msg.contains("Sending") && msg.contains("size = 0")) {
gotZeroSize.set(true);
}
}
};
appender.start();
Logger.getRootLogger().addAppender(appender);
LOG.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
LOG.addAppender(appender);
LOG.setLevel(Level.TRACE);
rootLogger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
rootLogger.addAppender(appender);
try {
brokerService = new BrokerService();
@ -89,7 +101,7 @@ public class AMQ3779Test {
brokerService.waitUntilStopped();
}
} finally {
Logger.getRootLogger().removeAppender(appender);
org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger()).removeAppender(appender);
}
}

View File

@ -45,10 +45,13 @@ import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.store.kahadb.plist.PListStoreImpl;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.apache.log4j.spi.LoggingEvent;
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.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -84,17 +87,21 @@ public class AMQ4221Test extends TestSupport {
@Override
public void setUp() throws Exception {
LogManager.getRootLogger().addAppender(new DefaultTestAppender() {
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
if (event.getLevel().isGreaterOrEqual(Level.ERROR)) {
public void append(LogEvent event) {
if (event.getLevel().isMoreSpecificThan(Level.WARN)) {
System.err.println("Fail on error in log: " + event.getMessage());
done.set(true);
errorsInLog.add(event.getRenderedMessage());
errorsInLog.add(event.getMessage().getFormattedMessage());
}
}
});
};
appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
done.set(false);
errorsInLog.clear();

View File

@ -41,10 +41,13 @@ import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.region.policy.PolicyEntry;
import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.log4j.Appender;
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;
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.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -61,7 +64,6 @@ public class AMQ5426Test {
private AtomicBoolean hasFailureInProducer = new AtomicBoolean(false);
private Thread producerThread;
private AtomicBoolean hasErrorInLogger;
private Appender errorDetectorAppender;
protected ConnectionFactory createConnectionFactory() throws Exception {
ActiveMQConnectionFactory conFactory = new ActiveMQConnectionFactory(
@ -92,25 +94,20 @@ public class AMQ5426Test {
// ActiveMQConnection.setClientInternalExceptionListener
// since ActiveMQMessageConsumer.dispatch will silently catch and
// discard any RuntimeException
errorDetectorAppender = new AppenderSkeleton() {
@Override
public void close() {
// Do nothing
}
@Override
public boolean requiresLayout() {
return false;
}
@Override
protected void append(LoggingEvent event) {
if (event.getLevel().isGreaterOrEqual(Level.ERROR))
hasErrorInLogger.set(true);
}
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void append(LogEvent event) {
if (event.getLevel().isMoreSpecificThan(Level.WARN))
hasErrorInLogger.set(true);
}
};
appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
org.apache.log4j.Logger.getRootLogger().addAppender(errorDetectorAppender);
producerThread = new Thread(new Runnable() {
@Override
public void run() {

View File

@ -31,16 +31,18 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.apache.log4j.Appender;
import org.apache.log4j.spi.LoggingEvent;
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.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.region.policy.AbortSlowConsumerStrategy;
import org.apache.activemq.broker.region.policy.PolicyEntry;
import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.transport.failover.FailoverTransport;
import org.apache.activemq.util.DefaultIOExceptionHandler;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.activemq.util.Wait;
import org.slf4j.Logger;
@ -75,26 +77,31 @@ public class AMQ5844Test {
static boolean abortingSlowConsumer = false;
static boolean successfullyReconnected = false;
static final AbstractAppender appender;
static final Appender appender = new DefaultTestAppender() {
@Override
public void doAppend(LoggingEvent event) {
if(event.getMessage().toString().contains("aborting slow consumer")) {
abortingSlowConsumer = true;
}
static {
appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void append(LogEvent event) {
if(event.getMessage().getFormattedMessage().contains("aborting slow consumer")) {
abortingSlowConsumer = true;
}
if(event.getMessage().toString().contains("Successfully reconnected to")) {
successfullyReconnected = true;
if(event.getMessage().getFormattedMessage().contains("Successfully reconnected to")) {
successfullyReconnected = true;
}
}
}
};
};
appender.start();
}
@BeforeClass
public static void setUp() throws Exception {
org.apache.log4j.Logger.getRootLogger().addAppender(appender);
org.apache.logging.log4j.core.Logger rootLogger = ((org.apache.logging.log4j.core.Logger)LogManager.getRootLogger());
rootLogger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
rootLogger.addAppender(appender);
}
@Before
/**
* Sets a AbortSlowConsumerStrategy policy entry on the broker and starts the broker.
@ -133,7 +140,7 @@ public class AMQ5844Test {
broker.stop();
broker.waitUntilStopped();
}
org.apache.log4j.Logger.getRootLogger().removeAppender(appender);
((org.apache.logging.log4j.core.Logger)LogManager.getRootLogger()).removeAppender(appender);
}
@Test

View File

@ -46,7 +46,7 @@ import org.apache.activemq.util.Wait.Condition;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.TrueFileFilter;
import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.apache.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -61,7 +61,8 @@ public class AMQ6131Test {
@Before
public void startBroker() throws Exception {
org.apache.log4j.Logger.getLogger(MessageDatabase.class).setLevel(Level.TRACE);
org.apache.logging.log4j.core.Logger logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(MessageDatabase.class));
logger.setLevel(org.apache.logging.log4j.Level.TRACE);
setUpBroker(true);
}

View File

@ -48,7 +48,8 @@ import org.apache.activemq.store.kahadb.MessageDatabase;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.TrueFileFilter;
import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.apache.log4j.Level;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -96,8 +97,7 @@ public class AMQ6133PersistJMSRedeliveryTest {
public void setup() throws Exception {
// Investigate loss of messages on message update in store.
org.apache.log4j.Logger.getLogger(MessageDatabase.class).setLevel(Level.TRACE);
((org.apache.logging.log4j.core.Logger)LogManager.getLogger(MessageDatabase.class)).setLevel(Level.TRACE);
createBroker(true);
}

View File

@ -22,11 +22,14 @@ import org.apache.activemq.broker.jmx.QueueViewMBean;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;
import org.apache.activemq.store.kahadb.MessageDatabase;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.activemq.util.Wait;
import org.apache.log4j.Appender;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;
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.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -85,22 +88,26 @@ public class AMQ6432Test {
@Test
public void testTransactedStoreUsageSuspendResume() throws Exception {
org.apache.log4j.Logger log4jLogger =
org.apache.log4j.Logger.getLogger(MessageDatabase.class);
final AtomicBoolean failed = new AtomicBoolean(false);
final File journalDataDir = ((KahaDBPersistenceAdapter) broker.getPersistenceAdapter()).getStore().getJournal().getDirectory();
Appender appender = new DefaultTestAppender() {
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(MessageDatabase.class));
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
if (event.getLevel().equals(Level.WARN) && event.getMessage().toString().startsWith("Failed to load next journal")) {
LOG.info("received unexpected log message: " + event.getMessage());
public void append(LogEvent event) {
if (event.getLevel().equals(Level.WARN) && event.getMessage().getFormattedMessage().startsWith("Failed to load next journal")) {
LOG.info("received unexpected log message: " + event.getMessage().getFormattedMessage());
failed.set(true);
}
}
};
log4jLogger.addAppender(appender);
appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
try {
ExecutorService sendExecutor = Executors.newSingleThreadExecutor();
@ -139,7 +146,7 @@ public class AMQ6432Test {
}));
} finally {
log4jLogger.removeAppender(appender);
logger.removeAppender(appender);
}
assertFalse("failed on unexpected log event", failed.get());

View File

@ -27,11 +27,16 @@ import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.broker.region.policy.VMPendingQueueMessageStoragePolicy;
import org.apache.activemq.broker.region.policy.VMPendingSubscriberMessageStoragePolicy;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.activemq.util.IOHelper;
import org.apache.activemq.util.Wait;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -48,7 +53,7 @@ public class AMQ6463Test extends JmsTestSupport {
ActiveMQQueue queueA = new ActiveMQQueue("QUEUE.A");
protected TransportConnector connector;
protected ActiveMQConnection connection;
protected DefaultTestAppender appender;
protected Appender appender;
final AtomicInteger errors = new AtomicInteger(0);
final AtomicBoolean gotUsageBlocked = new AtomicBoolean();
@ -120,25 +125,28 @@ public class AMQ6463Test extends JmsTestSupport {
public void setUp() throws Exception {
setAutoFail(true);
appender = new DefaultTestAppender() {
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
public void append(LogEvent event) {
if (event.getLevel().equals(Level.ERROR)) {
errors.incrementAndGet();
} else if (event.getLevel().equals(Level.WARN) && event.getRenderedMessage().contains("Usage Manager Memory Limit")) {
} else if (event.getLevel().equals(Level.WARN) && event.getMessage().getFormattedMessage().contains("Usage Manager Memory Limit")) {
gotUsageBlocked.set(true);
}
}
};
org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger();
rootLogger.addAppender(appender);
appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
super.setUp();
}
protected void tearDown() throws Exception {
org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger();
rootLogger.removeAppender(appender);
org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger()).removeAppender(appender);
if (connection != null) {
connection.close();

View File

@ -21,6 +21,7 @@ import org.apache.activemq.ActiveMQXAConnection;
import org.apache.activemq.ActiveMQXAConnectionFactory;
import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TransportConnection;
import org.apache.activemq.broker.jmx.BrokerMBeanSupport;
import org.apache.activemq.broker.jmx.BrokerViewMBean;
import org.apache.activemq.broker.jmx.DestinationViewMBean;
@ -34,7 +35,8 @@ import org.apache.activemq.store.kahadb.MessageDatabase;
import org.apache.activemq.util.JMXSupport;
import org.apache.activemq.util.Wait;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Level;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -166,8 +168,8 @@ public class AMQ7067Test {
public void testXAPrepareWithAckCompactionDoesNotLooseInflight() throws Exception {
// investigate liner gc issue - store usage not getting released
org.apache.log4j.Logger.getLogger(MessageDatabase.class).setLevel(Level.TRACE);
org.apache.logging.log4j.core.Logger logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(MessageDatabase.class));
logger.setLevel(org.apache.logging.log4j.Level.TRACE);
setupXAConnection();
@ -242,8 +244,7 @@ public class AMQ7067Test {
((KahaDBPersistenceAdapter)broker.getPersistenceAdapter()).setCompactAcksAfterNoGC(2);
// investigate liner gc issue - store usage not getting released
org.apache.log4j.Logger.getLogger(MessageDatabase.class).setLevel(Level.TRACE);
org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(MessageDatabase.class)).setLevel(Level.TRACE);
setupXAConnection();

View File

@ -34,11 +34,14 @@ import org.apache.activemq.store.kahadb.MultiKahaDBPersistenceAdapter;
import org.apache.activemq.store.kahadb.MultiKahaDBTransactionStore;
import org.apache.activemq.store.kahadb.disk.journal.Journal;
import org.apache.activemq.util.ByteSequence;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.activemq.util.Wait;
import org.apache.log4j.Appender;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;
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.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.After;
import org.junit.Test;
import org.slf4j.Logger;
@ -280,20 +283,22 @@ public class MKahaDBTxRecoveryTest {
corruptTxStoreJournal(pathToDataDir);
// verify failure to load txStore via logging
org.apache.log4j.Logger log4jLogger =
org.apache.log4j.Logger.getLogger(MultiKahaDBTransactionStore.class);
AtomicBoolean foundSomeCorruption = new AtomicBoolean();
Appender appender = new DefaultTestAppender() {
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(MultiKahaDBTransactionStore.class));
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
if (event.getLevel().equals(Level.ERROR) && event.getMessage().toString().startsWith("Corrupt ")) {
public void append(LogEvent event) {
if (Level.ERROR.equals(event.getLevel()) && event.getMessage().getFormattedMessage().startsWith("Corrupt ")) {
LOG.info("received expected log message: " + event.getMessage());
foundSomeCorruption.set(true);
}
}
};
log4jLogger.addAppender(appender);
appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
try {
prepareBrokerWithMultiStore(false);
@ -367,7 +372,7 @@ public class MKahaDBTxRecoveryTest {
assertEquals(101, destination.getMessageStore().getMessageCount());
} finally {
log4jLogger.removeAppender(appender);
logger.removeAppender(appender);
}
}
@ -401,24 +406,26 @@ public class MKahaDBTxRecoveryTest {
corruptTxStoreJournalAndTruncate(pathToDataDir);
// verify failure to load txStore via logging
org.apache.log4j.Logger log4jLogger =
org.apache.log4j.Logger.getLogger(MultiKahaDBTransactionStore.class);
AtomicBoolean foundSomeCorruption = new AtomicBoolean();
AtomicBoolean ignoringCorruption = new AtomicBoolean();
Appender appender = new DefaultTestAppender() {
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(MultiKahaDBTransactionStore.class));
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
if (event.getLevel().equals(Level.ERROR) && event.getMessage().toString().startsWith("Corrupt ")) {
public void append(LogEvent event) {
if (Level.ERROR.equals(event.getLevel()) && event.getMessage().getFormattedMessage().startsWith("Corrupt ")) {
LOG.info("received expected log message: " + event.getMessage());
foundSomeCorruption.set(true);
} else if (event.getLevel().equals(Level.INFO) && event.getMessage().toString().contains("auto resolving")) {
} else if (Level.INFO.equals(event.getLevel()) && event.getMessage().getFormattedMessage().contains("auto resolving")) {
ignoringCorruption.set(true);
}
}
};
log4jLogger.addAppender(appender);
appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
try {
prepareBrokerWithMultiStore(false);
@ -453,7 +460,7 @@ public class MKahaDBTxRecoveryTest {
broker.stop();
} finally {
log4jLogger.removeAppender(appender);
logger.removeAppender(appender);
}
}

View File

@ -38,7 +38,8 @@ import org.apache.activemq.TestSupport;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;
import org.apache.activemq.store.kahadb.MessageDatabase;
import org.apache.log4j.Level;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@ -108,7 +109,7 @@ public class TransactedStoreUsageSuspendResumeTest {
public void setup() throws Exception {
// investigate liner gc issue - store usage not getting released
org.apache.log4j.Logger.getLogger(MessageDatabase.class).setLevel(Level.TRACE);
org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(MessageDatabase.class)).setLevel(Level.TRACE);
broker = new BrokerService();
broker.setDeleteAllMessagesOnStartup(true);

View File

@ -41,7 +41,8 @@ import org.apache.activemq.store.jdbc.TransactionContext;
import org.apache.activemq.util.IOHelper;
import org.apache.activemq.util.LeaseLockerIOExceptionHandler;
import org.apache.derby.jdbc.EmbeddedDataSource;
import org.apache.log4j.Level;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -109,7 +110,7 @@ public class TrapMessageInJDBCStoreTest extends TestCase {
public void testDBCommitException() throws Exception {
org.apache.log4j.Logger serviceLogger = org.apache.log4j.Logger.getLogger(TransportConnection.class.getName() + ".Service");
org.apache.logging.log4j.core.Logger serviceLogger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(TransportConnection.class.getName() + ".Service"));
serviceLogger.setLevel (Level.TRACE);
broker = this.createBroker(false);

View File

@ -26,12 +26,13 @@ import javax.jms.MessageProducer;
import javax.jms.Session;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class EmbeddedActiveMQ
{
private static Logger logger = Logger.getLogger(EmbeddedActiveMQ.class);
private static Logger logger = LoggerFactory.getLogger(EmbeddedActiveMQ.class);
public static void main(String[] args)
{

View File

@ -18,11 +18,13 @@ package org.apache.activemq.bugs.embedded;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ThreadExplorer
{
static Logger logger = Logger.getLogger(ThreadExplorer.class);
static Logger logger = LoggerFactory.getLogger(ThreadExplorer.class);
public static Thread[] listThreads()
{

View File

@ -35,11 +35,14 @@ import org.apache.activemq.broker.jmx.BrokerMBeanSupport;
import org.apache.activemq.broker.jmx.ManagementContext;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Appender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggingEvent;
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.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.Test;
import static org.apache.activemq.broker.util.JMXAuditLogEntry.VERBS;
@ -119,31 +122,33 @@ public class JmxAuditLogTest extends TestSupport
@Test
public void testPasswordsAreNotLoggedWhenAuditIsTurnedOn() throws Exception
{
Logger log4jLogger = Logger.getLogger("org.apache.activemq.audit");
log4jLogger.setLevel(Level.INFO);
final var log4jLogger = (org.apache.logging.log4j.core.Logger)LogManager.getLogger("org.apache.activemq.audit");
Configurator.setLevel("org.apache.activemq.audit", Level.INFO);
final AtomicInteger logCount = new AtomicInteger(0);
final AtomicBoolean gotEnded = new AtomicBoolean(false);
Appender appender = new DefaultTestAppender()
{
@Override
public void doAppend(LoggingEvent event)
{
if (event.getMessage() instanceof String)
{
String message = (String) event.getMessage();
System.out.println(message);
if (message.contains("testPassword"))
{
fail("Password should not appear in log file");
}
if (message.contains(VERBS[1])) {
gotEnded.set(true);
}
}
logCount.incrementAndGet();
}
// start new
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void append(LogEvent event) {
if (event.getMessage() != null)
{
String message = event.getMessage().getFormattedMessage();
System.out.println(message);
if (message.contains("testPassword"))
{
fail("Password should not appear in log file");
}
if (message.contains(VERBS[1])) {
gotEnded.set(true);
}
}
logCount.incrementAndGet();
}
};
appender.start();
log4jLogger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
log4jLogger.addAppender(appender);
MBeanServerConnection conn = createJMXConnector(portToUse);
@ -163,8 +168,6 @@ public class JmxAuditLogTest extends TestSupport
@Test
public void testNameTargetVisible() throws Exception
{
Logger log4jLogger = Logger.getLogger("org.apache.activemq.audit");
log4jLogger.setLevel(Level.INFO);
final AtomicInteger logCount = new AtomicInteger(0);
final AtomicBoolean gotEnded = new AtomicBoolean(false);
final AtomicBoolean gotQueueName = new AtomicBoolean(false);
@ -172,36 +175,41 @@ public class JmxAuditLogTest extends TestSupport
final AtomicBoolean gotConnectorName = new AtomicBoolean(false);
final String queueName = queue.getQueueName();
Appender appender = new DefaultTestAppender()
{
@Override
public void doAppend(LoggingEvent event)
{
if (event.getMessage() instanceof String)
{
String message = (String) event.getMessage();
System.out.println(message);
if (message.contains(VERBS[0])) {
if (message.contains(queueName)) {
gotQueueName.set(true);
}
if (message.contains(broker.getBrokerName())) {
gotBrokerName.set(true);
}
if (message.contains("TCP")) {
gotConnectorName.set(true);
}
}
// start new
final var logger = (org.apache.logging.log4j.core.Logger)LogManager.getLogger("org.apache.activemq.audit");
Configurator.setLevel("org.apache.activemq.audit", Level.INFO);
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void append(LogEvent event) {
if (event.getMessage() != null)
{
String message = event.getMessage().getFormattedMessage();
System.out.println(message);
if (message.contains(VERBS[0])) {
if (message.contains(queueName)) {
gotQueueName.set(true);
}
if (message.contains(broker.getBrokerName())) {
gotBrokerName.set(true);
}
if (message.contains(VERBS[1])) {
gotEnded.set(true);
}
}
logCount.incrementAndGet();
}
if (message.contains("TCP")) {
gotConnectorName.set(true);
}
}
if (message.contains(VERBS[1])) {
gotEnded.set(true);
}
}
logCount.incrementAndGet();
}
};
log4jLogger.addAppender(appender);
appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
MBeanServerConnection conn = createJMXConnector(portToUse);
ObjectName queueObjName = new ObjectName(broker.getBrokerObjectName() + ",destinationType=Queue,destinationName=" + queueName);
@ -226,7 +234,6 @@ public class JmxAuditLogTest extends TestSupport
assertEquals("got messages", 6, logCount.get());
assertTrue("got connectorName in called statement", gotConnectorName.get());
log4jLogger.removeAppender(appender);
logger.removeAppender(appender);
}
}

View File

@ -45,8 +45,9 @@ import org.apache.activemq.broker.jmx.QueueViewMBean;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.transport.stomp.StompConnection;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Appender;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.LogEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -71,17 +72,17 @@ public class SecurityJMXTest extends TestCase {
final AtomicReference<Object> stackTrace = new AtomicReference<Object>();
final Appender appender = new DefaultTestAppender() {
public void doAppend(LoggingEvent event) {
String message = event.getMessage().toString();
@Override
public void append(LogEvent event) {
String message = event.getMessage().getFormattedMessage();
if (message.contains("Async error occurred")) {
gotExpected.set(true);
stackTrace.set(event.getThrowableInformation());
stackTrace.set(event.getThrown());
}
}
};
final org.apache.log4j.Logger toVerify = org.apache.log4j.Logger.getLogger(TransportConnection.class.getName() + ".Service");
org.apache.logging.log4j.core.Logger toVerify = (org.apache.logging.log4j.core.Logger)LogManager.getLogger(TransportConnection.class.getName() + ".Service");
toVerify.addAppender(appender);
try {

View File

@ -27,14 +27,18 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.activemq.broker.LockableServiceSupport;
import org.apache.activemq.broker.Locker;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.activemq.util.IOHelper;
import org.apache.activemq.util.LockFile;
import org.apache.activemq.util.ServiceStopper;
import org.apache.activemq.util.Wait;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggingEvent;
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.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
@ -86,16 +90,22 @@ public class SharedFileLockerTest {
private void internalLoop(long timewait) throws Exception {
final AtomicInteger logCounts = new AtomicInteger(0);
DefaultTestAppender appender = new DefaultTestAppender() {
// start new
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
if (event.getLevel() == Level.INFO) {
public void append(LogEvent event) {
if (Level.INFO.equals(event.getLevel())) {
logCounts.incrementAndGet();
}
}
};
appender.start();
Logger.getRootLogger().addAppender(appender);
Configurator.setRootLevel(Level.DEBUG);
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
final AtomicInteger errors = new AtomicInteger(0);
@ -163,8 +173,7 @@ public class SharedFileLockerTest {
} finally {
Logger.getRootLogger().removeAppender(appender);
logger.removeAppender(appender);
// to make sure we won't leak threads if the test ever failed for any reason
thread.join(1000);
@ -182,14 +191,18 @@ public class SharedFileLockerTest {
public void verifyLockAcquireWaitsForLockDrop() throws Exception {
final AtomicInteger logCounts = new AtomicInteger(0);
DefaultTestAppender appender = new DefaultTestAppender() {
// start new
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(SharedFileLocker.class));
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
public void append(LogEvent event) {
logCounts.incrementAndGet();
}
};
Logger sharedFileLogger = Logger.getLogger(SharedFileLocker.class);
sharedFileLogger.addAppender(appender);
appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
LockableServiceSupport config = new LockableServiceSupport() {
@ -261,7 +274,7 @@ public class SharedFileLockerTest {
executorService.shutdownNow();
underTest.stop();
lockFile.delete();
sharedFileLogger.removeAppender(appender);
logger.removeAppender(appender);
}
}
}

View File

@ -23,9 +23,14 @@ import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.region.RegionBroker;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.util.DefaultIOExceptionHandler;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Appender;
import org.apache.log4j.Level;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -61,22 +66,31 @@ public class JDBCConcurrentDLQTest {
broker.start();
broker.waitUntilStarted();
appender = new DefaultTestAppender() {
final var jdbcLogger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(JDBCPersistenceAdapter.class));
final var regionLogger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(RegionBroker.class));
appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(org.apache.log4j.spi.LoggingEvent event) {
if (event.getLevel().toInt() > Level.INFO_INT) {
LOG.error("Got error from log:" + event.getRenderedMessage());
public void append(LogEvent event) {
if (event.getLevel().isMoreSpecificThan(Level.INFO)) {
LOG.error("Got error from log:" + event.getMessage().getFormattedMessage());
gotError.set(true);
}
}
};
appender.start();
jdbcLogger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
jdbcLogger.addAppender(appender);
regionLogger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
regionLogger.addAppender(appender);
}
@After
public void tearDown() throws Exception {
org.apache.log4j.Logger.getLogger(RegionBroker.class).removeAppender(appender);
org.apache.log4j.Logger.getLogger(JDBCPersistenceAdapter.class).removeAppender(appender);
((org.apache.logging.log4j.core.Logger)LogManager.getLogger(RegionBroker.class)).removeAppender(appender);
((org.apache.logging.log4j.core.Logger)LogManager.getLogger(JDBCPersistenceAdapter.class)).removeAppender(appender);
broker.stop();
}
@ -108,8 +122,15 @@ public class JDBCConcurrentDLQTest {
gotError.set(true);
}
});
org.apache.log4j.Logger.getLogger(RegionBroker.class).addAppender(appender);
org.apache.log4j.Logger.getLogger(JDBCPersistenceAdapter.class).addAppender(appender);
final var loggerRB = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(RegionBroker.class));
final var loggerJDBC = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(JDBCPersistenceAdapter.class));
loggerRB.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
loggerRB.addAppender(appender);
loggerJDBC.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
loggerJDBC.addAppender(appender);
final int numMessages = 100;
final AtomicInteger consumed = new AtomicInteger(numMessages);

View File

@ -48,8 +48,13 @@ import org.apache.activemq.util.IOHelper;
import org.apache.activemq.util.LeaseLockerIOExceptionHandler;
import org.apache.activemq.util.Wait;
import org.apache.derby.jdbc.EmbeddedDataSource;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;
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.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -124,25 +129,27 @@ public class JDBCIOExceptionHandlerTest {
final AtomicBoolean connectorStarted = new AtomicBoolean(false);
final AtomicBoolean connectorStopped = new AtomicBoolean(false);
DefaultTestAppender appender = new DefaultTestAppender() {
// start new
final var rootLogger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
if (event.getMessage().toString().startsWith("JMX consoles can connect to")) {
public void append(LogEvent event) {
if (event.getMessage().getFormattedMessage().startsWith("JMX consoles can connect to")) {
connectorStarted.set(true);
}
if (event.getMessage().toString().equals("Stopping jmx connector")) {
if (event.getMessage().getFormattedMessage().equals("Stopping jmx connector")) {
connectorStopped.set(true);
}
}
};
appender.start();
org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger();
Level previousLevel = rootLogger.getLevel();
rootLogger.setLevel(Level.DEBUG);
rootLogger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
rootLogger.addAppender(appender);
rootLogger.setLevel(Level.DEBUG);
// end new
BrokerService broker = new BrokerService();
broker.getManagementContext().setCreateConnector(true);

View File

@ -20,14 +20,15 @@ import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.store.PersistenceAdapter;
import org.apache.activemq.store.PersistenceAdapterTestSupport;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Appender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.LogEvent;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.logging.log4j.core.config.Configurator;
/**
*
@ -53,19 +54,20 @@ public class KahaDBPersistenceAdapterTest extends PersistenceAdapterTestSupport
Appender appender = new DefaultTestAppender() {
@Override
public void doAppend(LoggingEvent event) {
public void append(LogEvent event) {
trappedLogMessages.set(true);
if (event.getLevel().equals(Level.INFO)) {
if (event.getMessage().toString().contains("Recovery replayed ")) {
if (event.getMessage() != null && event.getMessage().getFormattedMessage().contains("Recovery replayed ")) {
gotSomeReplay.set(true);
}
}
}
};
appender.start();
try {
Logger.getLogger(MessageDatabase.class.getName()).addAppender(appender);
Logger.getLogger(MessageDatabase.class.getName()).setLevel(Level.INFO);
Configurator.setLevel(MessageDatabase.class.getName(), Level.INFO);
((org.apache.logging.log4j.core.Logger)LogManager.getLogger(MessageDatabase.class)).addAppender(appender);
brokerService = new BrokerService();
pa = createPersistenceAdapter(false);
@ -73,8 +75,9 @@ public class KahaDBPersistenceAdapterTest extends PersistenceAdapterTestSupport
brokerService.start();
} finally {
Logger.getRootLogger().removeAppender(appender);
Logger.getLogger(MessageDatabase.class.getName()).removeAppender(appender);
appender.stop();
((org.apache.logging.log4j.core.Logger)LogManager.getRootLogger()).removeAppender(appender);
((org.apache.logging.log4j.core.Logger)LogManager.getLogger(MessageDatabase.class)).removeAppender(appender);
}
assertTrue("log capture working", trappedLogMessages.get());
assertFalse("no replay message in the log", gotSomeReplay.get());

View File

@ -32,10 +32,13 @@ import junit.framework.TestCase;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggingEvent;
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.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
/**
* @author chirino
@ -209,16 +212,19 @@ public class KahaDBTest extends TestCase {
kaha.setCheckForCorruptJournalFiles(true);
final AtomicBoolean didSomeRecovery = new AtomicBoolean(false);
DefaultTestAppender appender = new DefaultTestAppender() {
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
if (event.getLevel() == Level.INFO && event.getRenderedMessage().contains("Recovering from the journal @")) {
public void append(LogEvent event) {
if (Level.INFO.equals(event.getLevel()) && event.getMessage().getFormattedMessage().contains("Recovering from the journal @")) {
didSomeRecovery.set(true);
}
}
};
appender.start();
Logger.getRootLogger().addAppender(appender);
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
broker = createBroker(kaha);
@ -226,7 +232,7 @@ public class KahaDBTest extends TestCase {
assertEquals("Expected to received all messages.", count, 100);
broker.stop();
Logger.getRootLogger().removeAppender(appender);
logger.removeAppender(appender);
assertFalse("Did not replay any records from the journal", didSomeRecovery.get());
}

View File

@ -43,7 +43,8 @@ import org.apache.activemq.broker.region.Destination;
import org.apache.activemq.broker.region.Queue;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.util.ServiceStopper;
import org.apache.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* TestCase showing the message-destroying described in AMQ-1925
@ -51,7 +52,7 @@ import org.apache.log4j.Logger;
*
*/
public class AMQ1925Test extends TestCase implements ExceptionListener {
private static final Logger log = Logger.getLogger(AMQ1925Test.class);
private static final Logger log = LoggerFactory.getLogger(AMQ1925Test.class);
private static final String QUEUE_NAME = "test.amq1925";
private static final String PROPERTY_MSG_NUMBER = "NUMBER";

View File

@ -33,12 +33,13 @@ import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TransportConnector;
import org.apache.activemq.network.NetworkConnector;
import org.apache.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FailoverUpdateURIsTest extends TestCase {
private static final String QUEUE_NAME = "test.failoverupdateuris";
private static final Logger LOG = Logger.getLogger(FailoverUpdateURIsTest.class);
private static final Logger LOG = LoggerFactory.getLogger(FailoverUpdateURIsTest.class);
String firstTcpUri = "tcp://localhost:61616";
String secondTcpUri = "tcp://localhost:61626";
@ -64,10 +65,10 @@ public class FailoverUpdateURIsTest extends TestCase {
String targetDir = "target/" + getName();
new File(targetDir).mkdir();
File updateFile = new File(targetDir + "/updateURIsFile.txt");
LOG.info(updateFile);
LOG.info(updateFile.toURI());
LOG.info(updateFile.getAbsoluteFile());
LOG.info(updateFile.getAbsoluteFile().toURI());
LOG.info("updateFile:" + updateFile);
LOG.info("updateFileUri:" + updateFile.toURI());
LOG.info("updateFileAbsoluteFile:" + updateFile.getAbsoluteFile());
LOG.info("updateFileAbsoluteFileUri:" + updateFile.getAbsoluteFile().toURI());
FileOutputStream out = new FileOutputStream(updateFile);
out.write(firstTcpUri.getBytes());
out.close();

View File

@ -17,21 +17,23 @@
package org.apache.activemq.transport.nio;
import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.net.ssl.SSLHandshakeException;
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.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TransportConnector;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -114,20 +116,24 @@ public class NIOSSLBasicTest {
final CountDownLatch gotLogMessage = new CountDownLatch(1);
final AtomicBoolean gotRemoteAddressInLog = new AtomicBoolean();
final DefaultTestAppender appender = new DefaultTestAppender() {
// start new
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
if (event.getLevel().equals(Level.WARN) && event.getRenderedMessage().contains("Could not accept connection")) {
public void append(LogEvent event) {
if (event.getLevel().equals(Level.WARN) && event.getMessage().getFormattedMessage().contains("Could not accept connection")) {
gotLogMessage.countDown();
if (event.getRenderedMessage().contains("tcp")) {
if (event.getMessage().getFormattedMessage().contains("tcp")) {
// got remote address
gotRemoteAddressInLog.set(true);
}
}
}
};
org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger();
rootLogger.addAppender(appender);
appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
BrokerService broker = null;
try {
@ -138,7 +144,7 @@ public class NIOSSLBasicTest {
if (broker != null) {
stopBroker(broker);
}
rootLogger.removeAppender(appender);
logger.removeAppender(appender);
assertTrue("Got remote address in log", gotRemoteAddressInLog.get());
}
}

View File

@ -19,11 +19,16 @@ package org.apache.activemq.transport.tcp;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TransportConnection;
import org.apache.activemq.broker.TransportConnector;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Appender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -32,7 +37,6 @@ import org.slf4j.LoggerFactory;
import javax.net.ssl.*;
import java.net.Socket;
import java.net.URI;
import java.sql.Time;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
@ -48,9 +52,11 @@ public class TcpTransportCloseSocketNoWarnTest {
public static final String PASSWORD = "password";
public static final String SERVER_KEYSTORE = "src/test/resources/server.keystore";
public static final String TRUST_KEYSTORE = "src/test/resources/client.keystore";
public static final Appender appender;
public static final AtomicBoolean gotExceptionInLog = new AtomicBoolean();
private BrokerService brokerService;
private Logger rootLogger;
static {
System.setProperty("javax.net.ssl.trustStore", TRUST_KEYSTORE);
@ -59,20 +65,20 @@ public class TcpTransportCloseSocketNoWarnTest {
System.setProperty("javax.net.ssl.keyStore", SERVER_KEYSTORE);
System.setProperty("javax.net.ssl.keyStorePassword", PASSWORD);
System.setProperty("javax.net.ssl.keyStoreType", KEYSTORE_TYPE);
}
final AtomicBoolean gotExceptionInLog = new AtomicBoolean();
Appender appender = new DefaultTestAppender() {
@Override
public void doAppend(LoggingEvent event) {
if (event.getLevel().equals(Level.WARN) && event.getRenderedMessage().contains("failed:")) {
gotExceptionInLog.set(Boolean.TRUE);
LOG.error("got event: " + event + ", ex:" + event.getRenderedMessage());
LOG.error("Event source: ", new Throwable("Here"));
appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void append(LogEvent event) {
if (event.getLevel().equals(Level.WARN) && event.getMessage().getFormattedMessage().contains("failed:")) {
gotExceptionInLog.set(Boolean.TRUE);
LOG.error("got event: " + event + ", ex:" + event.getMessage().getFormattedMessage());
LOG.error("Event source: ", new Throwable("Here"));
}
return;
}
return;
}
};
};
appender.start();
}
@Before
public void before() throws Exception {
@ -80,8 +86,11 @@ public class TcpTransportCloseSocketNoWarnTest {
brokerService.setPersistent(false);
brokerService.setUseJmx(false);
Logger.getRootLogger().addAppender(appender);
Logger.getLogger(TransportConnection.class.getName() + ".Transport").setLevel(Level.WARN);
rootLogger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
rootLogger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
rootLogger.addAppender(appender);
org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(TransportConnection.class.getName() + ".Transport")).setLevel(Level.WARN);
}
@After
@ -90,7 +99,7 @@ public class TcpTransportCloseSocketNoWarnTest {
brokerService.stop();
brokerService.waitUntilStopped();
}
Logger.getRootLogger().removeAppender(appender);
rootLogger.removeAppender(appender);
}
@Test(timeout = 60000)

View File

@ -18,10 +18,15 @@ package org.apache.activemq.transport.tcp;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TransportConnector;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.activemq.util.Wait;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -59,7 +64,7 @@ public class TcpTransportInactiveDuringHandshakeTest {
}
private BrokerService brokerService;
private DefaultTestAppender appender;
private Appender appender;
CountDownLatch inactivityMonitorFired;
CountDownLatch handShakeComplete;
@ -71,23 +76,24 @@ public class TcpTransportInactiveDuringHandshakeTest {
inactivityMonitorFired = new CountDownLatch(1);
handShakeComplete = new CountDownLatch(1);
appender = new DefaultTestAppender() {
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
if (event.getLevel().equals(Level.WARN) && event.getRenderedMessage().contains("InactivityIOException")) {
public void append(LogEvent event) {
if (Level.WARN.equals(event.getLevel()) && event.getMessage().getFormattedMessage().contains("InactivityIOException")) {
inactivityMonitorFired.countDown();
}
}
};
org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger();
rootLogger.addAppender(appender);
appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
}
@After
public void after() throws Exception {
org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger();
rootLogger.removeAppender(appender);
org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger()).removeAppender(appender);;
if (brokerService != null) {
brokerService.stop();

View File

@ -35,10 +35,14 @@ import org.apache.activemq.command.ActiveMQTopic;
import org.apache.activemq.network.DurableConduitBridge;
import org.apache.activemq.network.NetworkConnector;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.activemq.util.Wait;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;
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.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.Ignore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -158,16 +162,20 @@ public class VmTransportNetworkBrokerTest extends TestCase {
vmConnection.close();
final AtomicInteger logCounts = new AtomicInteger(0);
DefaultTestAppender appender = new DefaultTestAppender() {
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(DurableConduitBridge.class));
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
if (event.getLevel() == Level.ERROR) {
public void append(LogEvent event) {
if (Level.ERROR.equals(event.getLevel())) {
logCounts.incrementAndGet();
}
}
};
appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
org.apache.log4j.Logger.getLogger(DurableConduitBridge.class).addAppender(appender);
try {
NetworkConnector networkConnector = forwarder.addNetworkConnector("static:("
@ -185,7 +193,7 @@ public class VmTransportNetworkBrokerTest extends TestCase {
assertEquals("no errors", 0, logCounts.get());
} finally {
org.apache.log4j.Logger.getLogger(DurableConduitBridge.class).removeAppender(appender);
logger.removeAppender(appender);
}
}

View File

@ -24,11 +24,13 @@ import org.apache.activemq.ConfigurationException;
import org.junit.Test;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggingEvent;
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.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@ -52,42 +54,50 @@ public class StoreUsageLimitsTest {
public void testCheckLimitsLogLevel() throws Exception {
final CountDownLatch foundMessage = new CountDownLatch(1);
DefaultTestAppender appender = new DefaultTestAppender() {
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
String message = (String) event.getMessage();
public void append(LogEvent event) {
String message = event.getMessage().getFormattedMessage();
if (message.contains(toMatch) && event.getLevel().equals(Level.WARN)) {
foundMessage.countDown();
}
}
};
appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
Logger.getRootLogger().addAppender(appender);
BrokerService brokerService = createBroker();
brokerService.start();
brokerService.stop();
assertTrue("Fount log message", foundMessage.await(WAIT_TIME_MILLS, TimeUnit.MILLISECONDS));
Logger.getRootLogger().removeAppender(appender);
logger.removeAppender(appender);
}
@Test
public void testCheckLimitsFailStart() throws Exception {
final CountDownLatch foundMessage = new CountDownLatch(1);
DefaultTestAppender appender = new DefaultTestAppender() {
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
String message = (String) event.getMessage();
public void append(LogEvent event) {
String message = event.getMessage().getFormattedMessage();
if (message.contains(toMatch) && event.getLevel().equals(Level.ERROR)) {
foundMessage.countDown();
}
}
};
appender.start();
Logger.getRootLogger().addAppender(appender);
BrokerService brokerService = createBroker();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
BrokerService brokerService = createBroker();
brokerService.setAdjustUsageLimits(false);
try {
brokerService.start();
@ -99,6 +109,6 @@ public class StoreUsageLimitsTest {
assertTrue("Fount log message", foundMessage.await(WAIT_TIME_MILLS, TimeUnit.MILLISECONDS));
Logger.getRootLogger().removeAppender(appender);
logger.removeAppender(appender);
}
}

View File

@ -19,12 +19,15 @@ package org.apache.activemq.usecases;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggingEvent;
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.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import javax.jms.Connection;
@ -49,16 +52,19 @@ public class AMQ6446Test {
final HashSet<String> loggers = new HashSet<String>();
final HashSet<String> messages = new HashSet<String>();
DefaultTestAppender appender = new DefaultTestAppender() {
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
public void append(LogEvent event) {
loggers.add(event.getLoggerName());
messages.add(event.getRenderedMessage());
messages.add(event.getMessage().getFormattedMessage());
}
};
appender.start();
Logger.getRootLogger().addAppender(appender);
Logger.getRootLogger().setLevel(Level.DEBUG);
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
Configurator.setRootLevel(Level.DEBUG);
String brokerUrlWithTrace = brokerService.getTransportConnectorByScheme("tcp").getPublishableConnectString() +
urlTraceParam;
@ -70,7 +76,7 @@ public class AMQ6446Test {
connections.add(c);
}
Logger.getRootLogger().removeAppender(appender);
logger.removeAppender(appender);
// no logger ends with :2
assertFalse(foundMatch(loggers, ".*:2$"));
@ -101,16 +107,19 @@ public class AMQ6446Test {
final HashSet<String> loggers = new HashSet<String>();
final HashSet<String> messages = new HashSet<String>();
DefaultTestAppender appender = new DefaultTestAppender() {
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
public void append(LogEvent event) {
loggers.add(event.getLoggerName());
messages.add(event.getRenderedMessage());
messages.add(event.getMessage().getFormattedMessage());
}
};
appender.start();
Logger.getRootLogger().addAppender(appender);
Logger.getRootLogger().setLevel(Level.TRACE);
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
Configurator.setRootLevel(Level.TRACE);
String brokerUrlWithTrace = brokerService.getTransportConnectorByScheme("tcp").getPublishableConnectString() +
legacySupportParam;
@ -122,7 +131,7 @@ public class AMQ6446Test {
connections.add(c);
}
Logger.getRootLogger().removeAppender(appender);
logger.removeAppender(appender);
// logger ends with :2
assertTrue(foundMatch(loggers, ".*:2$"));

View File

@ -30,11 +30,12 @@ import org.apache.activemq.JmsMultipleBrokersTestSupport;
import org.apache.activemq.broker.TransportConnection;
import org.apache.activemq.broker.TransportConnector;
import org.apache.activemq.command.ConnectionControl;
import org.apache.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;
public class ClientRebalanceTest extends JmsMultipleBrokersTestSupport {
private static final Logger LOG = Logger.getLogger(ClientRebalanceTest.class);
private static final Logger LOG = LoggerFactory.getLogger(ClientRebalanceTest.class);
private static final String QUEUE_NAME = "Test.ClientRebalanceTest";
protected void setUp() throws Exception {

View File

@ -23,10 +23,13 @@ import org.apache.activemq.broker.region.cursors.AbstractStoreCursor;
import org.apache.activemq.broker.region.policy.PolicyEntry;
import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.command.ActiveMQTopic;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Appender;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;
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.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -99,24 +102,26 @@ public class DurableSubCacheTest {
publishMesssages(topic, 20);
org.apache.log4j.Logger log4jLogger = org.apache.log4j.Logger.getLogger(AbstractStoreCursor.class.getCanonicalName());
final AtomicBoolean failed = new AtomicBoolean(false);
Appender appender = new DefaultTestAppender() {
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(AbstractStoreCursor.class));
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
if (event.getLevel() == Level.WARN) {
LOG.info("Got warn event:" + event.getRenderedMessage());
public void append(LogEvent event) {
if (Level.WARN.equals(event.getLevel())) {
LOG.info("Got warn event:" + event.getMessage().getFormattedMessage());
failed.set(true);
}
}
};
log4jLogger.addAppender(appender);
appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
try {
consumeDurableSub(topic, "my_sub_1", 20, prefetch);
} finally {
log4jLogger.removeAppender(appender);
logger.removeAppender(appender);
}
assertFalse("no warning from the cursor", failed.get());

View File

@ -22,9 +22,6 @@ import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;
import org.apache.activemq.store.kahadb.MessageDatabase;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.spi.LoggingEvent;
import org.junit.experimental.theories.Theories;
import javax.jms.Connection;
import javax.jms.DeliveryMode;
@ -34,6 +31,14 @@ import javax.jms.Session;
import javax.jms.TextMessage;
import java.util.concurrent.atomic.AtomicBoolean;
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.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
public class EmptyTransactionTest extends TestCase {
private static final int CHECKPOINT_INTERVAL = 500;
@ -42,16 +47,20 @@ public class EmptyTransactionTest extends TestCase {
public void testEmptyTransactionsCheckpoint() throws Exception {
AtomicBoolean hadRecovery = new AtomicBoolean(false);
DefaultTestAppender appender = new DefaultTestAppender() {
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(MessageDatabase.class));
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
if (event.getMessage().toString().contains("Recovering from the journal @")) {
hadRecovery.set(true);
}
public void append(LogEvent event) {
if (event.getMessage().toString().contains("Recovering from the journal @")) {
hadRecovery.set(true);
}
}
};
appender.start();
org.apache.log4j.Logger.getLogger(MessageDatabase.class).addAppender(appender);
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
start(true);

View File

@ -30,11 +30,14 @@ import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQTopic;
import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.activemq.util.Wait;
import org.apache.log4j.Appender;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;
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.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -119,23 +122,25 @@ public class OfflineDurableSubscriberTimeoutTest extends org.apache.activemq.Tes
public void testOfflineDurableSubscriberTimeout() throws Exception {
final AtomicBoolean foundLogMessage = new AtomicBoolean(false);
Appender appender = new DefaultTestAppender() {
// start new
final var loggerMRB = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(ManagedRegionBroker.class));
final var loggerTopic = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(org.apache.activemq.broker.region.Topic.class));
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
if (event.getLevel().isGreaterOrEqual(Level.WARN)) {
public void append(LogEvent event) {
if (event.getLevel().isLessSpecificThan(Level.WARN)) {
LOG.info("received unexpected log message: " + event.getMessage());
foundLogMessage.set(true);
}
}
};
appender.start();
org.apache.log4j.Logger log4jLoggerMRB =
org.apache.log4j.Logger.getLogger(ManagedRegionBroker.class);
org.apache.log4j.Logger log4jLoggerT =
org.apache.log4j.Logger.getLogger(org.apache.activemq.broker.region.Topic.class);
loggerMRB.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
loggerMRB.addAppender(appender);
log4jLoggerMRB.addAppender(appender);
log4jLoggerT.addAppender(appender);
loggerTopic.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
loggerTopic.addAppender(appender);
try {
@ -199,8 +204,8 @@ public class OfflineDurableSubscriberTimeoutTest extends org.apache.activemq.Tes
assertFalse("have not found any log warn/error", foundLogMessage.get());
} finally {
log4jLoggerMRB.removeAppender(appender);
log4jLoggerT.removeAppender(appender);
loggerMRB.removeAppender(appender);
loggerTopic.removeAppender(appender);
}
}

View File

@ -52,9 +52,13 @@ import org.apache.activemq.network.DemandForwardingBridgeSupport;
import org.apache.activemq.network.NetworkBridge;
import org.apache.activemq.network.NetworkConnector;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Appender;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;
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.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -85,7 +89,7 @@ public class RequestReplyTempDestRemovalAdvisoryRaceTest extends JmsMultipleBrok
protected final AtomicBoolean shutdown = new AtomicBoolean(false);
HashSet<NetworkConnector> networkConnectors = new HashSet<NetworkConnector>();
HashSet<Connection> advisoryConsumerConnections = new HashSet<Connection>();
Appender slowDownAppender;
AbstractAppender slowDownAppender;
CountDownLatch consumerDemandExists;
@ -263,15 +267,16 @@ public class RequestReplyTempDestRemovalAdvisoryRaceTest extends JmsMultipleBrok
private void slowDownAdvisoryDispatch() throws Exception {
org.apache.log4j.Logger.getLogger(DemandForwardingBridgeSupport.class).setLevel(Level.DEBUG);
org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(DemandForwardingBridgeSupport.class)).setLevel(Level.DEBUG);
// instrument a logger to block the processing of a remove sub advisory
// simulate a slow thread
slowDownAppender = new DefaultTestAppender() {
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
slowDownAppender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent loggingEvent) {
if (Level.DEBUG.equals(loggingEvent.getLevel())) {
String message = loggingEvent.getMessage().toString();
public void append(LogEvent event) {
if (Level.DEBUG.equals(event.getLevel())) {
String message = event.getMessage().getFormattedMessage();
if (message.startsWith("BrokerB") && message.contains("remove local subscription")) {
// sleep for a bit
try {
@ -285,8 +290,10 @@ public class RequestReplyTempDestRemovalAdvisoryRaceTest extends JmsMultipleBrok
}
}
};
slowDownAppender.start();
org.apache.log4j.Logger.getRootLogger().addAppender(slowDownAppender);
logger.get().addAppender(slowDownAppender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(slowDownAppender);
}
@Override
@ -320,7 +327,7 @@ public class RequestReplyTempDestRemovalAdvisoryRaceTest extends JmsMultipleBrok
@Override
protected void tearDown() throws Exception {
if (slowDownAppender != null) {
org.apache.log4j.Logger.getRootLogger().removeAppender(slowDownAppender);
org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger()).removeAppender(slowDownAppender);
}
for (Connection connection : advisoryConsumerConnections) {
connection.close();

View File

@ -35,17 +35,19 @@ import org.apache.activemq.ActiveMQPrefetchPolicy;
import org.apache.activemq.advisory.AdvisorySupport;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TransportConnection;
import org.apache.activemq.broker.region.RegionBroker;
import org.apache.activemq.broker.region.Topic;
import org.apache.activemq.broker.region.policy.PolicyEntry;
import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQTopic;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.activemq.util.Wait;
import org.apache.log4j.Appender;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;
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.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -141,18 +143,21 @@ public class TopicProducerFlowControlTest extends TestCase implements MessageLis
});
final AtomicInteger warnings = new AtomicInteger();
Appender appender = new DefaultTestAppender() {
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(Topic.class));
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
if (event.getLevel().equals(Level.WARN) && event.getMessage().toString().contains("Usage Manager memory limit reached")) {
public void append(LogEvent event) {
if (event.getLevel().equals(Level.WARN) && event.getMessage().getFormattedMessage().contains("Usage Manager memory limit reached")) {
LOG.info("received log message: " + event.getMessage());
warnings.incrementAndGet();
}
}
};
org.apache.log4j.Logger log4jLogger =
org.apache.log4j.Logger.getLogger(Topic.class);
log4jLogger.addAppender(appender);
appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
try {
// Start producing the test messages
@ -204,7 +209,7 @@ public class TopicProducerFlowControlTest extends TestCase implements MessageLis
assertTrue("warning limited", warnings.get() < blockedCounter.get());
} finally {
log4jLogger.removeAppender(appender);
logger.removeAppender(appender);
}
}
@ -234,20 +239,22 @@ public class TopicProducerFlowControlTest extends TestCase implements MessageLis
Session listenerSession = c.createSession(false, 1);
Destination destination = createDestination(listenerSession);
final AtomicInteger warnings = new AtomicInteger();
Appender appender = new DefaultTestAppender() {
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(Topic.class));
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
if (event.getLevel().equals(Level.WARN) && event.getMessage().toString().contains("Usage Manager memory limit reached")) {
public void append(LogEvent event) {
if (event.getLevel().equals(Level.WARN) && event.getMessage().getFormattedMessage().contains("Usage Manager memory limit reached")) {
LOG.info("received log message: " + event.getMessage());
warnings.incrementAndGet();
}
}
};
org.apache.log4j.Logger log4jLogger =
org.apache.log4j.Logger.getLogger(Topic.class);
log4jLogger.addAppender(appender);
appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
try {
// Start producing the test messages
@ -319,7 +326,7 @@ public class TopicProducerFlowControlTest extends TestCase implements MessageLis
assertEquals("nothing sent during close", enqueueCountWhenBlocked, broker.getDestination(ActiveMQDestination.transform(destination)).getDestinationStatistics().getEnqueues().getCount());
}
} finally {
log4jLogger.removeAppender(appender);
logger.removeAppender(appender);
}
}

View File

@ -26,10 +26,13 @@ import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.usage.SystemUsage;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Appender;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;
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.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import javax.jms.*;
import java.io.File;
import java.io.IOException;
@ -134,18 +137,22 @@ public class UsageBlockedDispatchTest extends TestSupport {
consumer.receive(messageReceiveTimeout);
final AtomicBoolean gotExpectedLogEvent = new AtomicBoolean(false);
Appender appender = new DefaultTestAppender() {
// start new
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(Queue.class));
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override
public void doAppend(LoggingEvent event) {
if (event.getLevel() == Level.WARN && event.getRenderedMessage().contains("cursor blocked")) {
public void append(LogEvent event) {
if (Level.WARN.equals(event.getLevel()) && event.getMessage().getFormattedMessage().contains("cursor blocked")) {
gotExpectedLogEvent.set(true);
}
}
};
appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
try {
org.apache.log4j.Logger.getLogger(Queue.class).addAppender(appender);
MessageConsumer noDispatchConsumer = consumerSession.createConsumer(shouldBeStuckForDispatch);
@ -154,8 +161,7 @@ public class UsageBlockedDispatchTest extends TestSupport {
assertTrue("Got the new warning about the blocked cursor", gotExpectedLogEvent.get());
} finally {
org.apache.log4j.Logger.getLogger(Queue.class).removeAppender(appender);
org.apache.log4j.Logger.getRootLogger().removeAppender(appender);
logger.removeAppender(appender);
}
}
}

View File

@ -1,47 +0,0 @@
## ---------------------------------------------------------------------------
## 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.
## ---------------------------------------------------------------------------
#
# The logging properties used during tests..
#
log4j.rootLogger=INFO, out, stdout
#log4j.logger.org.apache.activemq.broker.scheduler=DEBUG
#log4j.logger.org.apache.activemq.store.kahadb.scheduler=DEBUG
#log4j.logger.org.apache.activemq.network.DemandForwardingBridgeSupport=DEBUG
#log4j.logger.org.apache.activemq.transport.failover=TRACE
#log4j.logger.org.apache.activemq.transport.TransportLogger.Connection=TRACE
#log4j.logger.org.apache.activemq.store.jdbc=TRACE
#log4j.logger.org.apache.activemq.store.kahadb=TRACE
#log4j.logger.org.apache.activemq.broker.region.cursors.AbstractStoreCursor=DEBUG
#log4j.logger.org.apache.activemq.store.jdbc.JDBCMessageStore=DEBUG
#log4j.logger.org.apache.activemq.store.kahadb.disk.journal=DEBUG
#log4j.logger.org.apache.activemq.store.kahadb.AbstractKahaDBStore=DEBUG
# CONSOLE appender not used by default
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] - %-5p %-30.30c{1} - %m%n
#log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] - %-5p %-30.30c{1} - %-10.10X{activemq.broker} %-20.20X{activemq.connector} %-10.10X{activemq.destination} - %m%n
# File appender
log4j.appender.out=org.apache.log4j.FileAppender
log4j.appender.out.layout=org.apache.log4j.PatternLayout
log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] - %-5p %-30.30c{1} - %m%n
#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] - %-5p %-30.30c{1} - %-10.10X{activemq.broker} %-20.20X{activemq.connector} %-10.10X{activemq.destination} - %m%n
log4j.appender.out.file=target/activemq-test.log
log4j.appender.out.append=true

View File

@ -0,0 +1,55 @@
## ---------------------------------------------------------------------------
## 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.
## ---------------------------------------------------------------------------
#
# The logging properties used during tests
#
rootLogger.level=INFO
rootLogger.appenderRef.console.ref=Console
rootLogger.appenderRef.logfile.ref=RollingFile
#logger.scheduler.name=org.apache.activemq.broker.scheduler
#logger.scheduler.level=DEBUG
#logger.network.name=org.apache.activemq.network.DemandForwardingBridgeSupport
#logger.network.level=DEBUG
#logger.failover.name=org.apache.activemq.transport.failover
#logger.failover.level=TRACE
#logger.jdbc.name=org.apache.activemq.store.jdbc
#logger.jdbc.level=TRACE
#logger.cursors.name=org.apache.activemq.broker.region.cursors.AbstractStoreCursor
#logger.cursors.level=DEBUG
# Console appender
appender.console.type=Console
appender.console.name=Console
appender.console.layout.type=PatternLayout
appender.console.layout.pattern=%d [%-15.15t] - %-5p %-30.30c{1} - %m%n
#appender.console.layout.pattern=%d [%-15.15t] - %-5p %-30.30c{1} - %-10.10X{activemq.broker} %-20.20X{activemq.connector} %-10.10X{activemq.destination} - %m%n
# RollingFile appender
appender.logfile.type=RollingRandomAccessFile
appender.logfile.name=RollingFile
appender.logfile.fileName=target/activemq-test.log
appender.logfile.filePattern=target/activemq-test.log.%i
appender.logfile.append=true
appender.logfile.layout.type=PatternLayout
appender.logfile.layout.pattern=%d [%-15.15t] - %-5p %-30.30c{1} - %m%n
#appender.logfile.layout.pattern=%d [%-15.15t] - %-5p %-30.30c{1} - %-10.10X{activemq.broker} %-20.20X{activemq.connector} %-10.10X{activemq.destination} - %m%n
appender.logfile.policies.type=Policies
appender.logfile.policies.size.type=SizeBasedTriggeringPolicy
appender.logfile.policies.size.size=1MB