Thursday, October 1, 2009

Pokemon Silver Rom For Vba

Log4J and JMSAppender

These days I'm struggling with Log4J. We come to the point.

I need to save text messages in a JMS queue under certain critical circumstances, typically the exceptions, that represent significant problems for my middleware. Apache ActiveMQ JMS broker is running and in my application server via RAR (Resource Adapter). The execution context of a WebApplication.

Well, for the correct operation of the JMSAppendervi need to configure it first in the log4j.properties :

log4j.appender.jms = org.apache.log4j.net.JMSAppender
log4j.appender.jms.InitialContextFactoryName = org.apache.activemq.jndi.ActiveMQInitialContextFactory
log4j.appender.jms.ProviderURL = tcp: / / localhost: 61616
log4j.appender.jms.TopicBindingName = sampleTopic
log4j.appender.jms.TopicConnectionFactoryBindingName = TCF

log4j.logger.it.lucia.test.logging.JMSLogger = fatal, jms

Ok, perfect. Let's say that if you have this particular requirement, I can imagine that you are confident enough with the log4j.properties and then I will not explain the meaning of the configuration.
only event, with the last line, set the logger "jms" in default "fatal" for my class it.lucia.test.logging.JMSLogger. This means that when you're going to use the method "log.fatal" within that particular class, not going to write to the log file but usually trigger an operation queuing in a transparent manner using the JMS API.


Of course this is not enough.
ActiveMQ requires that the objects defined above in the log4j.properties, are also defined in the file jndi.properties , although the same objects are already set up jndi and reach of the web application using a regular object InitialContext. Let's then define the ConnectionFactory and the topic on which you want to log messages. Here's what you need to enter into the jndi.properties:


java.naming.factory.initial = org.apache . activemq.jndi.ActiveMQInitialContextFactory
java.naming.provider.url = vm: / / localhost
connectionFactoryNames = TCF =
topic.sampleTopic sampleTopic

Remember that jndi.properties must be within your classpath and then a good place to put it is the root of your package so then to find it in your classes once they are completed.


It 's done. Now you just call from your code:


Logger log = Logger.getLogger (this.getClass.getName ());
....
log.fatal ("This text will be loaded as a message in sampleTopic Topic ");

Beware that the call" log.fatal "act on JMSAppend er only when we make the call from within the class JMSLogger, the invocations" log.fatal " made from other classes are going to log sull'appender default (typically the log file and the terminal) or set on appender via log4j.properties.

For the moment is everything. The next .

0 comments:

Post a Comment