title: How to use JMS Appender?
body: <p>Inmy research about JMS Appenders I've found <a href="http://activemq.apache.org/how-do-i-use-log4j-jms-appender-with-activemq.html" rel="nofollow">turorial1</a> and <a href="http://code.google.com/p/log4j-jms-sample/wiki/ConfigurationGuide" rel="nofollow">tutorial2</a> . I've tried to follow them, but I couldn't run example program.</p>
  
  <p>Fistly I created file log4j.properties</p>
  
  <pre><code>log4j.rootLogger=INFO, stdout, jms
  
  #
  log4j.logger.org.apache.activemq=INFO, stdout
  
  log4j.appender.stdout=org.apache.log4j.ConsoleAppender
  log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
  log4j.appender.stdout.layout.ConversionPattern=%d %-5p %c - %m%n
  
  #
  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=logTopic
  log4j.appender.jms.TopicConnectionFactoryBindingName=ConnectionFactory
  </code></pre>
  
  <p>and jndi.properties</p>
  
  <pre><code>topic.logTopic=logTopic
  </code></pre>
  
  <p>Then I added Receiver.java to my project</p>
  
  <pre><code>public class Receiver implements MessageListener {
  
      public Receiver() throws Exception {
          ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
          Connection conn = factory.createConnection();
          Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
          conn.start();
          MessageConsumer consumer = sess.createConsumer(sess.createTopic("logTopic"));
          consumer.setMessageListener(this);
          Logger log = Logger.getLogger(Receiver.class);
  
          log.info("Test log");
  
          Thread.sleep(1000);
          consumer.close();
          sess.close();
          conn.close();
          System.exit(1);
      }
  
      public static void main(String[] args) throws Exception {
          new Receiver();
      }
  
      @Override
      public void onMessage(Message message) {
          try {
              // receive log event in your consumer
              LoggingEvent event = (LoggingEvent)((ActiveMQObjectMessage)message).getObject();
              System.out.println("Received log [" + event.getLevel() + "]: "+ event.getMessage());
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>I need make Receiver to gather all logs from project, but I cannot even run this simple example. Probably I don't know how to configure it correctly, because I get this output:</p>
  
  <pre><code>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.
  </code></pre>
  
  <p>Did I miss adding some lines in code or some files to classpath? I'm new to log4j.</p>
  
  <p>EDIT:
  I set Logger in <code>AspectJ</code> class. But I think that also in <code>Receiver</code> Logger is created and log is sent, so probably it should be done in <code>Receiver</code>, not in other class in my project.</p>
  
  <pre><code>static final Logger logger = Logger.getLogger(ReportingAspect.class);
  
  @Before("setLoggingFile()")
  public void setProperties() {
      PropertyConfigurator.configure("log4j.properties");
  }
  
  ProjectJMS
  |
  \_ src
  |   \_ packages...
  \_jndi.propeties
  \_log4j.properties
  </code></pre>