-
1. Re: log4j JMSAppender
pra Aug 9, 2002 6:52 AM (in response to perseios)Hi, as far as I know you are not wrong. When log4j is configured there is no JMS support in the running server, so you cant log to JMS then.
One solution (which I use) is to write an MBean and let it be started after JMS has come up which programatically ads the JMS appender.
Here are the code in the startService I use (with a custom appander, if you use the log4j one you should probably also set a layout):
public void startService() throws Exception
{
Category root = Category.getRoot();
Enumeration apps = root.getAllAppenders();
// We need to do it this way, otherwise we end up in a loop.
// All logging in org.jboss.mq is delegated to this category,
// and all appenders from the root hierachy is added to it.
// But logging calles here are not allowed to go higher
// than this, because we will then get a loop.
mq = Category.getInstance("org.jboss.mq");
mq.setAdditivity(false);
while(apps.hasMoreElements()) {
mq.addAppender((Appender)apps.nextElement());
}
// Threashold not used yet
appender = new JmsLogger();
appender.setTopicConnectionFactoryBindingName(topicConnectionFactoryBindingName);
appender.setTopicBindingName( topicBindingName );
appender.setName("JMS");
appender.activateOptions();
Category.getRoot().addAppender(appender);
// Change the stdout/stderr mappings, we do not like debugging to
// sterr ass ERR priority!
out = System.out;
err = System.err;
Category category = Category.getInstance("Default");
System.setOut(new CategoryStream(category, Priority.DEBUG, out));
System.setErr(new CategoryStream(category, Priority.WARN, err));
}
//Peter -
2. Re: log4j JMSAppender
pra Aug 9, 2002 6:57 AM (in response to perseios)Hm, my comment disapeared.
As far as I know it is not possible to use the example, since no JMS stuff is up and running when log4j is initialized. One way to solve it is to programatically set the JMS appender up in an MBean AFTER the JMS system ha come up.
I have done that (but with a custom appander, with the log4j one you probably have to set the Layout to). Here's the start method:
/**
* Set up the JMS logger.
*/
public void startService() throws Exception
{
Category root = Category.getRoot();
Enumeration apps = root.getAllAppenders();
// We need to do it this way, otherwise we end up in a loop.
// All logging in org.jboss.mq is delegated to this category,
// and all appenders from the root hierachy is added to it.
// But logging calles here are not allowed to go higher
// than this, because we will then get a loop.
mq = Category.getInstance("org.jboss.mq");
mq.setAdditivity(false);
while(apps.hasMoreElements()) {
mq.addAppender((Appender)apps.nextElement());
}
// Threashold not used yet
appender = new JmsLogger();
appender.setTopicConnectionFactoryBindingName(topicConnectionFactoryBindingName);
appender.setTopicBindingName( topicBindingName );
appender.setName("JMS");
appender.activateOptions();
Category.getRoot().addAppender(appender);
// Change the stdout/stderr mappings, we do not like debugging to
// sterr ass ERR priority!
out = System.out;
err = System.err;
Category category = Category.getInstance("Default");
System.setOut(new CategoryStream(category, Priority.DEBUG, out));
System.setErr(new CategoryStream(category, Priority.WARN, err));
}
//Peter -
3. Re: log4j JMSAppender
perseios Aug 19, 2002 1:48 AM (in response to perseios)thank you peter,
I have been absent two weeks, so I didn't reply inmediately.