You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Abhijit Arunachalam <Ab...@nbci.com> on 2001/01/26 03:07:39 UTC

Problem using BasicConfigurator

Hi,
First of all, I'd like to thank all the members of the 
log4j Team for building this library, it's really
useful and the article is correct, truly addictive.

I've just started using log4j for my project and am running into
some problems. Have gone over the docs and manuals, tried various hacks
to get this working, but can't seem to get it working.

basically, I want to change the layout format used by the BasicConfigurator
without adding another appender, but can't seem to figure out a way to do
so.





I've given the source below.
--------
import org.apache.log4j.*;
import java.util.*;

class Main
{
  static Category m_RootCategory = Category.getInstance("log");
  static Category m_Category = Category.getInstance("log.Main");
  static {
     BasicConfigurator.configure();
  }
  
  public static void main(String args[])
  {
    m_RootCategory.setPriority(Priority.WARN);
    // set this layout for all appenders
    
    String conversionSpecifier = new String("DATE=%d{ISO8601} PRTY=%p JBID=1
GCTX=%c MESG=%m \n");
    Layout layout = new PatternLayout(conversionSpecifier);
    Appender app = new FileAppender(layout,System.out);
    m_RootCategory.addAppender(app);

    m_Category.error("error ");
    m_Category.warn("error ");
    m_Category.info("error ");
    m_Category.debug("error ");
    
   // A a = new A();
   //B b = new B();
  }
};

The output I'm getting is in the form:
---------
$ java Main
DATE=2001-01-25 17:52:52,801 PRTY=ERROR JBID=1 GCTX=log.Main MESG=error
0 [main] ERROR log.Main  - error
DATE=2001-01-25 17:52:52,821 PRTY=WARN JBID=1 GCTX=log.Main MESG=error
30 [main] WARN log.Main  - error


What I want is just the messages below, in my Console:
----
DATE=2001-01-25 17:52:52,801 PRTY=ERROR JBID=1 GCTX=log.Main MESG=error
DATE=2001-01-25 17:52:52,821 PRTY=WARN JBID=1 GCTX=log.Main MESG=error

How can I turn off:
"30 [main] WARN log.Main  - error"  type log messages being inserted?

thanks in advance,
-abhi


Abhijit Arunachalam
CAT Group
NBCi
off : 415 375 5384
cell: 213 804 0988

------------------------------------
you are
      what you do
              when it counts !
                      - The Masao    





RE: NDC and RMI

Posted by Rex Madden <re...@microcreditcard.com>.
Thanks Wes.  Yeah, those are pretty much the conclusions that I came to.
Basically, I’m starting to add contextInfo params to all of my RMI method
calls, passing the data using NDC.get(), and then pushing that data onto the
NDC once I get into the RMI method.  Not as transparent as I’d like it to
be, but it works.  I figure, at least if I’m consistent in naming the param,
it’ll be easy to identify and remove if I need to.

I just posted an inquiry to the java rmi mailing list, so hopefully they’ll
have a solution.  I’ll keep my fingers crossed.  At the very least, I’ll bet
we’ll get a few more log4j devotees.

Thanks again,
Rex

-----Original Message-----
From: Wes [mailto:wesyah234@yahoo.com]
Sent: Friday, January 26, 2001 11:06 AM
To: LOG4J Users Mailing List
Subject: Re: NDC and RMI

I'm also working with RMI, and I'm using 2 techniques to differentiate the
log messages inside an RMI server object.

1. I use the %t conversion pattern to print the current thread.  With RMI
services, I see something like RMI TCP Connection(1988)-172.30.50.133, and
the number between "()" is unique for each rmi connection.  This at least
tells me the ip of the client, and the unique number separates the
connections.  It doesn't, however, give you any link back to the actual
process on that machine.  (For that, I'd say you have to pass something into
your RMI service, which is 2.)

2. Some rmi method calls take a parameter that can uniquely tie back to a
particular client request.  I then use that parameter to set the NDC at the
start of the rmi method, and pop it off at the end of the method.

I also wish there was a way to tie the client to the server for logging
purposes without manually passing some identifier to the server...  I
suppose this would be a good question for an RMI users mailing list!

Wes
----- Original Message -----
From: Rex Madden <ma...@microcreditcard.com>
To: LOG4J Users Mailing List <ma...@jakarta.apache.org>
Sent: Thursday, January 25, 2001 9:52 PM
Subject: NDC and RMI

Howdy all,

I have a web app that uses servlets, which in turn call some RMI business
objects.  I use the NDC class to store contextual information with the
servlets (I store IP address, session id, etc.) and would like to give that
information to the RMI objects.  But since the RMI objects are running in
their own thread, the only way I can think of to do it is to pass the
contextual data explicitly.  Obviously, it would be much better to get that
data to the RMI objects without having to add parameters to my function
calls.  I suspect that there’s not much I can do about it, but if anybody
has a better suggestion, I would appreciate it.

Thanks in advance,
Rex

Re: NDC and RMI

Posted by Wes <we...@yahoo.com>.
Problem using BasicConfiguratorI'm also working with RMI, and I'm using 2 techniques to differentiate the log messages inside an RMI server object.

1. I use the %t conversion pattern to print the current thread.  With RMI services, I see something like RMI TCP Connection(1988)-172.30.50.133, and the number between "()" is unique for each rmi connection.  This at least tells me the ip of the client, and the unique number separates the connections.  It doesn't, however, give you any link back to the actual process on that machine.  (For that, I'd say you have to pass something into your RMI service, which is 2.)

2. Some rmi method calls take a parameter that can uniquely tie back to a particular client request.  I then use that parameter to set the NDC at the start of the rmi method, and pop it off at the end of the method.

I also wish there was a way to tie the client to the server for logging purposes without manually passing some identifier to the server...  I suppose this would be a good question for an RMI users mailing list!

Wes
  ----- Original Message ----- 
  From: Rex Madden 
  To: LOG4J Users Mailing List 
  Sent: Thursday, January 25, 2001 9:52 PM
  Subject: NDC and RMI


  Howdy all, 

   

  I have a web app that uses servlets, which in turn call some RMI business objects.  I use the NDC class to store contextual information with the servlets (I store IP address, session id, etc.) and would like to give that information to the RMI objects.  But since the RMI objects are running in their own thread, the only way I can think of to do it is to pass the contextual data explicitly.  Obviously, it would be much better to get that data to the RMI objects without having to add parameters to my function calls.  I suspect that there's not much I can do about it, but if anybody has a better suggestion, I would appreciate it.

   

  Thanks in advance,

  Rex


NDC and RMI

Posted by Rex Madden <re...@microcreditcard.com>.
Howdy all,

I have a web app that uses servlets, which in turn call some RMI business
objects.  I use the NDC class to store contextual information with the
servlets (I store IP address, session id, etc.) and would like to give that
information to the RMI objects.  But since the RMI objects are running in
their own thread, the only way I can think of to do it is to pass the
contextual data explicitly.  Obviously, it would be much better to get that
data to the RMI objects without having to add parameters to my function
calls.  I suspect that there’s not much I can do about it, but if anybody
has a better suggestion, I would appreciate it.

Thanks in advance,
Rex

RE: Problem using BasicConfigurator

Posted by Rex Madden <re...@microcreditcard.com>.
Take out the BasicConfigurator.configure() statement.  That statement is a
shortcut to setting up the Category with a simple pattern.  Since your doing
manual configuration, the System.out appender will get added to the root
category twice.  See the troubleshooting guide…there’s a section on
duplicate log entries, which is essentially what you’re getting, except with
two different formats.

Rex

-----Original Message-----
From: Abhijit Arunachalam [mailto:Abhijit.Arunachalam@nbci.com]
Sent: Thursday, January 25, 2001 9:08 PM
To: log4j-user@jakarta.apache.org
Subject: Problem using BasicConfigurator


Hi,
First of all, I'd like to thank all the members of the
log4j Team for building this library, it's really
useful and the article is correct, truly addictive.
I've just started using log4j for my project and am running into
some problems. Have gone over the docs and manuals, tried various hacks
to get this working, but can't seem to get it working.
basically, I want to change the layout format used by the BasicConfigurator
without adding another appender, but can't seem to figure out a way to do
so.




I've given the source below.
--------
import org.apache.log4j.*;
import java.util.*;
class Main
{ 
  static Category m_RootCategory = Category.getInstance("log"); 
  static Category m_Category = Category.getInstance("log.Main"); 
  static { 
     BasicConfigurator.configure(); 
  } 
  
  public static void main(String args[]) 
  { 
    m_RootCategory.setPriority(Priority.WARN); 
    // set this layout for all appenders 
    
    String conversionSpecifier = new String("DATE=%d{ISO8601} PRTY=%p JBID=1 GCTX=%c MESG=%m \n"); 
    Layout layout = new PatternLayout(conversionSpecifier); 
    Appender app = new FileAppender(layout,System.out); 
    m_RootCategory.addAppender(app); 
    m_Category.error("error "); 
    m_Category.warn("error "); 
    m_Category.info("error "); 
    m_Category.debug("error "); 
    
   // A a = new A(); 
   //B b = new B(); 
  } 
}; 
The output I'm getting is in the form: 
--------- 
$ java Main 
DATE=2001-01-25 17:52:52,801 PRTY=ERROR JBID=1 GCTX=log.Main MESG=error 
0 [main] ERROR log.Main  - error 
DATE=2001-01-25 17:52:52,821 PRTY=WARN JBID=1 GCTX=log.Main MESG=error 
30 [main] WARN log.Main  - error 
 
What I want is just the messages below, in my Console: 
---- 
DATE=2001-01-25 17:52:52,801 PRTY=ERROR JBID=1 GCTX=log.Main MESG=error 
DATE=2001-01-25 17:52:52,821 PRTY=WARN JBID=1 GCTX=log.Main MESG=error 
How can I turn off: 
"30 [main] WARN log.Main  - error"  type log messages being inserted? 
thanks in advance, 
-abhi 
 
Abhijit Arunachalam 
CAT Group 
NBCi 
off : 415 375 5384 
cell: 213 804 0988 
------------------------------------ 
you are 
      what you do 
              when it counts ! 
                      - The Masao