log4j with OpenJMS  
Author Message
dmorin





PostPosted: 2003-9-22 22:51:00 Top

java-programmer, log4j with OpenJMS
Anybody got sample code for sending log4j messages specifically to OpenJMS?
In particular I'd like to do it all programmatically, since I'm working with a fairly complex pre-existing build system and would rather not start introducing too many new properties files. I have a log4j.properties file, but I'm trying to avoid having to create a jndi.properties file.

I stuck this code from OpenJMS in my Logging utility (which wraps log4j):

Hashtable properties = new Hashtable();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"org.exolab.jms.jndi.InitialContextFactory");
properties.put(Context.PROVIDER_URL, "rmi://localhost:1099/");
Context context = new InitialContext(properties);

and log4j.properties has a simple:
log4j.myLogger=DEBUG, JMS1
log4j.appender.JMS1=org.apache.log4j.net.JMSAppender
log4j.appender.JMS1.TopicBindingName=testtopic
log4j.appender.JMS1.TopicConnectionFactoryBindingName=JmsTopicConnectionFactory


I keep getting the error "javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial" which leads me to believe that my block of code is not storing the InitialContext in a way so that log4j can get at it.

Thanks!
 
dmorin





PostPosted: 2003-9-23 0:03:00 Top

java-programmer >> log4j with OpenJMS Never mind, fixed my own error. Once I put InitialContextFactoryName and
ProviderURL into the log4j.properties instead of trying to do it in
code, everything worked fine.

Duane

In article <v%Dbb.549125$o%2.240783@sccrnsc02>,
Duane Morin <email***@***.com> wrote:
>
>Anybody got sample code for sending log4j messages specifically to OpenJMS?
>In particular I'd like to do it all programmatically, since I'm working
>with a fairly complex pre-existing build system and would rather not
>start introducing too many new properties files. I have a
>log4j.properties file, but I'm trying to avoid having to create a
>jndi.properties file.
>
>I stuck this code from OpenJMS in my Logging utility (which wraps log4j):
>
> Hashtable properties = new Hashtable();
> properties.put(Context.INITIAL_CONTEXT_FACTORY,
> "org.exolab.jms.jndi.InitialContextFactory");
> properties.put(Context.PROVIDER_URL, "rmi://localhost:1099/");
> Context context = new InitialContext(properties);
>
>and log4j.properties has a simple:
>log4j.myLogger=DEBUG, JMS1
>log4j.appender.JMS1=org.apache.log4j.net.JMSAppender
>log4j.appender.JMS1.TopicBindingName=testtopic
>log4j.appender.JMS1.TopicConnectionFactoryBindingName=JmsTopicConnectionFactory
>
>
>I keep getting the error "javax.naming.NoInitialContextException: Need
>to specify class name in environment or system property, or as an applet
>parameter, or in an application resource file:
>java.naming.factory.initial" which leads me to believe that my block of
>code is not storing the InitialContext in a way so that log4j can get at
>it.
>
>Thanks!