Mark Womack | 1 May 02:18 2003

RE: Log4J and JMS

Do you have your own code that can successfully send messages across this
topic, configured the same way?  Code that is not related to log4j.  If so,
how does it compare to the code in the log4j JMSAppender?

-Mark

> -----Original Message-----
> From: Vivek Kapadekar [mailto:vkapadekar <at> bitfone.com]
> Sent: Wednesday, April 30, 2003 10:14 AM
> To: Log4J Users List
> Subject: RE: Log4J and JMS
> 
> 
> Hi All
> I tried many ways, but everytime it seems, it comes to the point where
> JMSAppender has to publish to the Topic and it just waits there.... It
> does not proceed from that point onwards.. 
> Here is another way I set all the properties inside the code:
> 
> 
>     Logger lo = Logger.getRootLogger();
>     JMSAppender jms = new JMSAppender();
>     jms.setInitialContextFactoryName(JNDI_FACTORY);
>     jms.setProviderURL("ormi://surya");
>     jms.setSecurityCredentials("bitfone");
>     jms.setSecurityPrincipalName("admin");
>    
> jms.setTopicConnectionFactoryBindingName("jms/theTopicConnecti
> onFactory");
>     jms.setTopicBindingName("jms/theTopic");
(Continue reading)

Brendon Co | 1 May 08:22 2003
Picon

RE: output file using log4j

another question, why is it the roll-over only occurd when I accessed a file that calls log4j?

Is it not automatic? I mean when it reaches 12:01pm, it should have roll-over, right? without calling
file/servlet/class that calls log4j...

-----Original Message-----
From: Ebersole, Steven [mailto:steven.ebersole <at> vignette.com]
Sent: Wednesday, April 30, 2003 10:28 PM
To: 'Log4J Users List'
Subject: RE: output file using log4j

log4j only uses the date pattern when rolling a file.  The current file is
_always_ named according to the File property.

log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A1.File=file.txt
log4j.appender.A4.DatePattern='.'yyyy-MM-dd

This will initially produce a file named file.txt.  

During first roll-over, the file named file.txt would be renamed to
file.txt.2003-04-29.  You would now have two files:
file.txt
file.txt.2003-04-29

During the next roll-over, file file.txt.2003-04-29 would remain unchanged
(unless it exceeds the max back up index property, in which case it would be
deleted).  file.txt would be renamed to file.txt.2003-04-30.  You would now
have three files:
file.txt
(Continue reading)

Lutz Michael | 1 May 14:02 2003
Picon

RE: output file using log4j


Generally speaking, the file rolls over during the first call to Log4j in a
new time period.

There has been discussion about a solution that would create a new file as
you describe, but I forget the details.  Hopefully someone will comment if
they've devised a solution.

-----Original Message-----
From: Brendon Co [mailto:Brendon.Co <at> asia.bigfoot.com]
Sent: Thursday, May 01, 2003 2:22 AM
To: Log4J Users List
Subject: RE: output file using log4j

another question, why is it the roll-over only occurd when I accessed a file
that calls log4j?

Is it not automatic? I mean when it reaches 12:01pm, it should have
roll-over, right? without calling file/servlet/class that calls log4j...

-----Original Message-----
From: Ebersole, Steven [mailto:steven.ebersole <at> vignette.com]
Sent: Wednesday, April 30, 2003 10:28 PM
To: 'Log4J Users List'
Subject: RE: output file using log4j

log4j only uses the date pattern when rolling a file.  The current file is
_always_ named according to the File property.

log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
(Continue reading)

Ebersole, Steven | 1 May 15:13 2003

RE: output file using log4j

I think you need to consider the logistics of actually implementing this
"ongoing rollover".  In essence, to accomplish this, you would need to spawn
a seperate non-terminating thread whose sole purpose was to watch a given
file and perform roll-over functionality.  The most likely solution would be
a seperate thread for each file to which log4j is writing.  Thats easily
becomes a system resource concern.

Personally, I like log4j as a simple, fairly unobtrusive tool which allows
me debug and track internal system state of my applications.  And even more
I like the fact that is has a very small memory footprint and minimizes
system resource consumption to get me those gains.  For me, logging is meant
to be logging; meaning that it is mostly peripherial to the intended purpose
of my application.  And as such I would not want it competing with my app
for access to those system resources.  But thats just my $.02

-----Original Message-----
From: Brendon Co [mailto:Brendon.Co <at> asia.bigfoot.com]
Sent: Thursday, May 01, 2003 1:22 AM
To: Log4J Users List
Subject: RE: output file using log4j

another question, why is it the roll-over only occurd when I accessed a file
that calls log4j?

Is it not automatic? I mean when it reaches 12:01pm, it should have
roll-over, right? without calling file/servlet/class that calls log4j...

-----Original Message-----
From: Ebersole, Steven [mailto:steven.ebersole <at> vignette.com]
Sent: Wednesday, April 30, 2003 10:28 PM
(Continue reading)

Vivek Kapadekar | 1 May 10:10 2003

RE: Log4J and JMS

  public static void main(String args[]) {
  TopicConnection connection = null;
  try {
    char answer = '\0';
    System.out.println("Getting Topic");
    InitialContext initContext = new InitialContext();
    TopicConnectionFactory factory =  
(TopicConnectionFactory)initContext.lookup("jms/theTopicConnectionFactory");

    connection = factory.createTopicConnection();
    Topic topic = (Topic)initContext.lookup(
        "jms/theTopic");

    TopicSession tsession =
connection.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
    TopicSubscriber tsubscriber = tsession.createSubscriber(topic);
    Listener topicListener = new Listener();
    tsubscriber.setMessageListener(topicListener);
    connection.start();
    InputStreamReader input = new InputStreamReader(System.in);
      while (!((answer=='q') )) {
        try {
          answer = (char)input.read();
        }
        catch(IOException ie){}
    }

  }
  catch (Exception e) {
      e.printStackTrace();
(Continue reading)

Ebersole, Steven | 1 May 17:19 2003

RE: Log4J and JMS

The entire LoggingEvent object is sent to the JMS server; it is wrapped in
an javax.jms.ObjectMessage.  Your subscriber code would instead need to be
something like:

  public void onMessage(Message message)
  { 
    try
    {
       System.out.println(" Got a message " + message);

       // Use the safer instanceof checking...
       if (ObjectMessage.class.isAssignableFrom( message.getClass() ))
       {
          Object obj = ((ObjectMessage)message).getObject();
          if (org.apache.log4j.LoggingEvent.class.isAssignableFrom(
obj.getClass() ))
          {
             // Handle the logging event, perhaps by formatting it...
          }
       }
    }
    catch(JMSException e)
    {
       System.out.println(" Exceptionin onMessage " + e.getMessage());
       e.printStackTrace();
    }

-----Original Message-----
From: Vivek Kapadekar [mailto:vkapadekar <at> bitfone.com]
Sent: Thursday, May 01, 2003 3:11 AM
(Continue reading)

Ebersole, Steven | 1 May 17:29 2003

RE: Log4J and JMS

Also, as an aside, message properties are not required things.  You might
want to read up on the JMS spec (or even the javadocs for some of these
objects).  Message properties are in essence application specific headers
and are mainly intended to be used in conjunction with message selectors.
The meaning here is that if I am writing a heavily JMS dependent app, I can
embed attributes that are completely custom to my app into these properties.
But they have nothing to do with JMS itself.

Log4j in and of itself is not really an app, and is by no means a JMS app.
Thus it has no need to set custom message properties.

-----Original Message-----
From: Vivek Kapadekar [mailto:vkapadekar <at> bitfone.com]
Sent: Thursday, May 01, 2003 3:11 AM
To: Log4J Users List
Subject: RE: Log4J and JMS

  public static void main(String args[]) {
  TopicConnection connection = null;
  try {
    char answer = '\0';
    System.out.println("Getting Topic");
    InitialContext initContext = new InitialContext();
    TopicConnectionFactory factory =  
(TopicConnectionFactory)initContext.lookup("jms/theTopicConnectionFactory");

    connection = factory.createTopicConnection();
    Topic topic = (Topic)initContext.lookup(
        "jms/theTopic");

(Continue reading)

Mark Womack | 1 May 17:36 2003

RE: Log4J and JMS

See the JMSSink class in the log4j release for code that "reads" the logging
event from a topic.

-Mark

> -----Original Message-----
> From: Ebersole, Steven [mailto:steven.ebersole <at> vignette.com]
> Sent: Thursday, May 01, 2003 8:20 AM
> To: 'Log4J Users List'
> Subject: RE: Log4J and JMS
> 
> 
> The entire LoggingEvent object is sent to the JMS server; it 
> is wrapped in
> an javax.jms.ObjectMessage.  Your subscriber code would 
> instead need to be
> something like:
> 
>   public void onMessage(Message message)
>   { 
>     try
>     {
>        System.out.println(" Got a message " + message);
> 
>        // Use the safer instanceof checking...
>        if (ObjectMessage.class.isAssignableFrom( message.getClass() ))
>        {
>           Object obj = ((ObjectMessage)message).getObject();
>           if (org.apache.log4j.LoggingEvent.class.isAssignableFrom(
> obj.getClass() ))
(Continue reading)

Vivek Kapadekar | 1 May 10:50 2003

RE: Log4J and JMS

It all worked finally.. this is the subscriber code snapshot
 try {
      if ( message instanceof ObjectMessage ) {
        ObjectMessage objMsg = (ObjectMessage) message;
        if ( objMsg.getObject() instanceof LoggingEvent) {
	   LoggingEvent logObject =(LoggingEvent)objMsg.getObject();
           System.out.println("Reading" +
logObject.getRenderedMessage());
      }
    }
    catch(JMSException e) {
      System.out.println(" Exceptionin onMessage " + e.getMessage());
      e.printStackTrace();
    }

Thanks very much for the help, especially Steve and Mark..Now am abt to
implement JMSAppender for Queues...

--Vivek
On Thu, 2003-05-01 at 08:29, Ebersole, Steven wrote:
> Also, as an aside, message properties are not required things.  You might
> want to read up on the JMS spec (or even the javadocs for some of these
> objects).  Message properties are in essence application specific headers
> and are mainly intended to be used in conjunction with message selectors.
> The meaning here is that if I am writing a heavily JMS dependent app, I can
> embed attributes that are completely custom to my app into these properties.
> But they have nothing to do with JMS itself.
> 
> Log4j in and of itself is not really an app, and is by no means a JMS app.
> Thus it has no need to set custom message properties.
(Continue reading)

Mark Womack | 1 May 17:57 2003

RE: Log4J and JMS

Yeah!  Steve did all the real work.  I was just the peanut gallery. :-)

Vivek, if you think your experience might be useful to future log4j users,
we'd appreciate it if you took the time to document your question and
solution on the log4j wiki:

http://nagoya.apache.org/wiki/apachewiki.cgi?Log4JProjectPages/FrequentlyAsk
edQuestions

thanks,
-Mark

> -----Original Message-----
> From: Vivek Kapadekar [mailto:vkapadekar <at> bitfone.com]
> Sent: Thursday, May 01, 2003 1:50 AM
> To: Log4J Users List
> Subject: RE: Log4J and JMS
> 
> 
> It all worked finally.. this is the subscriber code snapshot
>  try {
>       if ( message instanceof ObjectMessage ) {
>         ObjectMessage objMsg = (ObjectMessage) message;
>         if ( objMsg.getObject() instanceof LoggingEvent) {
> 	   LoggingEvent logObject =(LoggingEvent)objMsg.getObject();
>            System.out.println("Reading" +
> logObject.getRenderedMessage());
>       }
>     }
>     catch(JMSException e) {
(Continue reading)


Gmane