The version of Apache log4j used by SoundHelix.
Clone
HTTPS:
git clone https://vervis.peers.community/repos/aEp6o
SSH:
git clone USERNAME@vervis.peers.community:aEp6o
Branches
Tags
- 1.3alpha-7
- CHAINSAW_2_SANDBOX_MERGE
- CORE_VERSION
- LEVEL_REPLACES_PRIORITY
- PREALPHA_1_3_AS_OF_2004_05_12
- PRE_CHAINSAW_MODEL_CONVERSION
- PRE_UGLI_MOVE
- TAG_CHAINSAW2_MOVE
- log4j-1.2.17
- log4j-1.2.17-rc1
- v1.3alpha8
- v1.3alpha8-temp
- v1_2_1
- v1_2_10-recalled
- v1_2_11
- v1_2_11_rc1
- v1_2_11rc3
- v1_2_12
- v1_2_12_rc1
- v1_2_12_rc2
- v1_2_12_rc3
- v1_2_12_rc4
- v1_2_12_rc5
- v1_2_12_rc6
- v1_2_13
- v1_2_13_rc1
- v1_2_13_rc2
- v1_2_13_site_update
- v1_2_14
- v1_2_14_maven
- v1_2_14_rc1
- v1_2_14_site_update
- v1_2_15
- v1_2_15_rc1
- v1_2_15_rc2
- v1_2_15_rc3
- v1_2_15_rc4
- v1_2_15_rc5
- v1_2_15_rc6
- v1_2_16
- v1_2_16_rc1
- v1_2_16_rc2
- v1_2_17
- v1_2_17-rc1
- v1_2_17_rc1
- v1_2_17_rc2
- v1_2_17_rc3
- v1_2_2
- v1_2_3
- v1_2_4
- v1_2_6
- v1_2_7
- v1_2_9
- v1_2_alpha0
- v1_2_alpha7
- v1_2beta1
- v1_2final
- v1_3alpha_1
- v1_3alpha_6
- v_1_0
- v_1_0_1
- v_1_0_4
- v_1_1
- v_1_1_1
- v_1_1_2
- v_1_1_3
- v_1_1_b1
- v_1_1b2
- v_1_1b3
- v_1_1b5
- v_1_1b6
- v_1_1b7
- v_1_2beta3
JMSQueueAppender.java
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.spi.ErrorHandler;
import org.apache.log4j.spi.ErrorCode;
import org.apache.log4j.helpers.LogLog;
import java.util.Hashtable;
import java.util.Properties;
import javax.jms.*;
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
/**
* A Simple JMS (P2P) Queue Appender.
*
* @author Ceki Gülcü
* @author Jamie Tsao
*/
public class JMSQueueAppender extends AppenderSkeleton {
protected QueueConnection queueConnection;
protected QueueSession queueSession;
protected QueueSender queueSender;
protected Queue queue;
String initialContextFactory;
String providerUrl;
String queueBindingName;
String queueConnectionFactoryBindingName;
public
JMSQueueAppender() {
}
/**
* The <b>InitialContextFactory</b> option takes a string value.
* Its value, along with the <b>ProviderUrl</b> option will be used
* to get the InitialContext.
*/
public void setInitialContextFactory(String initialContextFactory) {
this.initialContextFactory = initialContextFactory;
}
/**
* Returns the value of the <b>InitialContextFactory</b> option.
*/
public String getInitialContextFactory() {
return initialContextFactory;
}
/**
* The <b>ProviderUrl</b> option takes a string value.
* Its value, along with the <b>InitialContextFactory</b> option will be used
* to get the InitialContext.
*/
public void setProviderUrl(String providerUrl) {
this.providerUrl = providerUrl;
}
/**
* Returns the value of the <b>ProviderUrl</b> option.
*/
public String getProviderUrl() {
return providerUrl;
}
/**
* The <b>QueueConnectionFactoryBindingName</b> option takes a
* string value. Its value will be used to lookup the appropriate
* <code>QueueConnectionFactory</code> from the JNDI context.
*/
public void setQueueConnectionFactoryBindingName(String queueConnectionFactoryBindingName) {
this.queueConnectionFactoryBindingName = queueConnectionFactoryBindingName;
}
/**
* Returns the value of the <b>QueueConnectionFactoryBindingName</b> option.
*/
public String getQueueConnectionFactoryBindingName() {
return queueConnectionFactoryBindingName;
}
/**
* The <b>QueueBindingName</b> option takes a
* string value. Its value will be used to lookup the appropriate
* destination <code>Queue</code> from the JNDI context.
*/
public void setQueueBindingName(String queueBindingName) {
this.queueBindingName = queueBindingName;
}
/**
Returns the value of the <b>QueueBindingName</b> option.
*/
public String getQueueBindingName() {
return queueBindingName;
}
/**
* Overriding this method to activate the options for this class
* i.e. Looking up the Connection factory ...
*/
public void activateOptions() {
QueueConnectionFactory queueConnectionFactory;
try {
Context ctx = getInitialContext();
queueConnectionFactory = (QueueConnectionFactory) ctx.lookup(queueConnectionFactoryBindingName);
queueConnection = queueConnectionFactory.createQueueConnection();
queueSession = queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue) ctx.lookup(queueBindingName);
queueSender = queueSession.createSender(queue);
queueConnection.start();
ctx.close();
} catch(Exception e) {
errorHandler.error("Error while activating options for appender named ["+name+
"].", e, ErrorCode.GENERIC_FAILURE);
}
}
protected InitialContext getInitialContext() throws NamingException {
try {
Hashtable ht = new Hashtable();
//Populate property hashtable with data to retrieve the context.
ht.put(Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
ht.put(Context.PROVIDER_URL, providerUrl);
return (new InitialContext(ht));
} catch (NamingException ne) {
LogLog.error("Could not get initial context with ["+initialContextFactory + "] and [" + providerUrl + "].");
throw ne;
}
}
protected boolean checkEntryConditions() {
String fail = null;
if(this.queueConnection == null) {
fail = "No QueueConnection";
} else if(this.queueSession == null) {
fail = "No QueueSession";
} else if(this.queueSender == null) {
fail = "No QueueSender";
}
if(fail != null) {
errorHandler.error(fail +" for JMSQueueAppender named ["+name+"].");
return false;
} else {
return true;
}
}
/**
* Close this JMSQueueAppender. Closing releases all resources used by the
* appender. A closed appender cannot be re-opened.
*/
public synchronized // avoid concurrent append and close operations
void close() {
if(this.closed)
return;
LogLog.debug("Closing appender ["+name+"].");
this.closed = true;
try {
if(queueSession != null)
queueSession.close();
if(queueConnection != null)
queueConnection.close();
} catch(Exception e) {
LogLog.error("Error while closing JMSQueueAppender ["+name+"].", e);
}
// Help garbage collection
queueSender = null;
queueSession = null;
queueConnection = null;
}
/**
* This method called by {@link AppenderSkeleton#doAppend} method to
* do most of the real appending work. The LoggingEvent will be
* be wrapped in an ObjectMessage to be put on the JMS queue.
*/
public void append(LoggingEvent event) {
if(!checkEntryConditions()) {
return;
}
try {
ObjectMessage msg = queueSession.createObjectMessage();
msg.setObject(event);
queueSender.send(msg);
} catch(Exception e) {
errorHandler.error("Could not send message in JMSQueueAppender ["+name+"].", e,
ErrorCode.GENERIC_FAILURE);
}
}
public boolean requiresLayout() {
return false;
}
}