Here is some actual working code. First, put a line like this at the top of your class definition:

private final Category log = Category.getInstance(getClass().getName());

Some will (rightly) point out that this is slightly inefficient as you could accomplish the same thing with a static, but that requires you to type in the name of your class explicitly. This code can be cut and pasted as is.

Then anywhere in your code, all you need to do is put statements like this wherever you wish to log:

      if (log.isInfoEnabled())
         log.info("ejbCreate() called");

You don't need the isInfoEnabled() conditional; it's just an optimization. That's it! All the log4j plumbing is already provided for you by JBoss. As to your question, "Category" is a standard log4j mechanism for grouping together related messages. Frequently, categories are just named after the class in which the log statements appear.

Marco Tedone wrote:
Sorry, I'm just coming from a quite complex log4j implementation with
Struts, and I'm using EJBs just as business components to query the
database, so I am not an EJB expert. What do you mean with category? Could
you please provide an example?

Thanks,

Marco


--__--__--

Message: 3
Date: Mon, 31 Mar 2003 16:22:06 -0500
From: Guy Rouillier <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Subject: Re: [JBoss-user] Is there a logger service available from Jboss?
Reply-To: [EMAIL PROTECTED]


Marco Tedone wrote:

Hi, I know that Jboss uses log4j; is there any service

available which


I could call from one of my Session Bean instead of

implementing all


the logger architecture [something like Log logger = (Log)context.lookUp("java:/Logger"); ]


What architecture? All you have to do to use log4j in an EJB is define the category (1 line of code) and then log.error(), log.info(),

etc.



-------------------------------------------------------
This SF.net email is sponsored by: ValueWeb: Dedicated Hosting for just $79/mo with 500 GB of bandwidth! No other company gives more support or power for your dedicated server
http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user




-------------------------------------------------------
This SF.net email is sponsored by: ValueWeb: Dedicated Hosting for just $79/mo with 500 GB of bandwidth! No other company gives more support or power for your dedicated server
http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to