6

I'm trying to run this example, but I have some problems with configuration.

I copied log4j-jms.properties, jndi.properties, Log4jJMSAppenderExample.java

ProjectJMS
|
\_ src
|   \_ Log4jJMSAppenderExample.java
|   \_ jndi.propeties
\_ log4j-jms.properties

and run activemq in my console.

When I ran my example I got

log4j:WARN No appenders could be found for logger (org.apache.activemq.transport.WireFormatNegotiator).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.`PropertyConfigurator.configure("log4j-jms.properties");`

so I added

PropertyConfigurator.configure("log4j-jms.properties");

Now I can see logs in Eclipse console, but still with this warning

log4j:WARN No appenders could be found for logger (org.apache.activemq.transport.WireFormatNegotiator).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
2012-08-13 10:21:44,741 INFO  Log4jJMSAppenderExample - Test log
Received log [INFO]: Test log

and in console with activemq I got

 WARN | Transport Connection to: tcp://127.0.0.1:2005 failed: java.net.SocketException: Connection reset

Why am I getting these warnings?

  1. Are my imports wrong?

    import javax.jms.Connection;
    import javax.jms.Message;
    import javax.jms.MessageConsumer;
    import javax.jms.MessageListener;
    import javax.jms.Session;
    
    import org.apache.activemq.ActiveMQConnectionFactory;
    import org.apache.activemq.command.ActiveMQObjectMessage;
    import org.apache.log4j.Logger;
    import org.apache.log4j.PropertyConfigurator;
    import org.apache.log4j.spi.LoggingEvent;
    
  2. Are my files in wrong place?

  3. How to set configuration file in Eclipse? Without using PropertyConfigurator.configure("log4j-jms.properties");? There is no line like this in example I follow.

alicjasalamon
  • 4,171
  • 15
  • 41
  • 65

3 Answers3

14

Your log4j.properties should reside inside the src folder. That way, Log4J will configure itself automatically, without you needing to write code.

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
  • 1
    I moved this file and in VM arguments added `-Dlog4j.configuration=log4j-jms.properties`. Works now, thanks. – alicjasalamon Aug 13 '12 at 08:58
  • Why do you need a `log4j-jms.properties`? You don't need this at all. `log4j.properties` is the system default configuration property for Log4J. – Buhake Sindi Aug 13 '12 at 08:59
  • I've made a mistake in my question. I named my file `log4j-jms.properties`, there is no `log4j.properties`. I can rename it, but it works OK. – alicjasalamon Aug 13 '12 at 09:05
  • 1
    Still, you don't need to create another properties file if the system-wide Log4J default properties work. – Buhake Sindi Aug 13 '12 at 09:58
  • @BuhakeSindi - Can you please help me with a related question - https://stackoverflow.com/questions/23278607/using-simple-log4j-properties-in-my-java-code – Erran Morad Apr 24 '14 at 20:03
2
  1. There is nothing about imports;

  2. It's not about the file place, as you see this message "log4j:WARN No appenders could be found for logger...", so please check the content of your log4j configuration file. Here's a demo:

    log4j.rootLogger=INFO, myConsoleAppender log4j.appender.myConsoleAppender=org.apache.log4j.ConsoleAppender log4j.appender.myConsoleAppender.layout=org.apache.log4j.PatternLayout log4j.appender.myConsoleAppender.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

  3. The default log4j configuration file is "log4j.properties", and as someone had said it should be place in the src folder.

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
aelbery
  • 21
  • 1
  • As I've said. I copied `log4j.properties` from tutorial, so it works OK. After adding additional argument to VM, I receive no warnings. – alicjasalamon Aug 13 '12 at 09:03
1

According to your project structure, there is no log4j-jms.properties.There is log4j.properties. So change your log4j properties file name.

Sai Ye Yan Naing Aye
  • 6,622
  • 12
  • 47
  • 65