Re: log4j and ejb usage ??

2001-05-09 Thread Ed Bras

Sorry that I posted the message three times. I was having a fight with my 
mail program!

Eddie


From: Eddie [EMAIL PROTECTED]
Reply-To: Orion-Interest [EMAIL PROTECTED]
To: Orion-Interest [EMAIL PROTECTED]
Subject: log4j and ejb usage ??
Date: Wed, 9 May 2001 16:13:50 +0200

Hellu there,

I wan to use log4j to do the following:
- Log a message and send an email if this concerns a log message of
typ=ERROR.
- Keep track of the logged message, so that a email is only send once and
not every minute when the same error keeps occuring.

Does anyone has any advice on how to do that. I was thinking about putting
it all in a session bean ??
Then what should I choose: stateless/statefull ??
I think that is best to give every application his own session bean, but I
can only do this by making the bean statefull. But if it statefull, the
application will have more session beans, as it is possible that more than
one client connect at the same time!! H :(

Some help please,
Eddie




_
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.





RE: log4j and ejb

2001-04-30 Thread Yves Bossel

We call log4j from JSP and from EJB.
We use a servlet to startup log4j: a servlet parameter passes the
configuration file name.

Here is the code:

public class InitLog4J extends HttpServlet {
private static final String PARAM_NAME_CONFIG_FILE =
configuration.file;

public void init(ServletConfig sconf) throws ServletException {
super.init(sconf);
//retrieve configuration file name
String cfg_file = sconf.getInitParameter(PARAM_NAME_CONFIG_FILE);
//check init parameter exists, else return
if (cfg_file == null) {
System.err.println(missing configuration parameter in web.xml:

   + PARAM_NAME_CONFIG_FILE);
System.err.println(Log4J will not be initialized.);
return;
}
//configure log4j
PropertyConfigurator.configure(cfg_file);
}
}

Add this to your web.xml
servlet
servlet-namefoo.bar.servlet.InitLog4J/servlet-name
display-nameInitialization Log4J/display-name
servlet-classfoo.bar.servlet.InitLog4J/servlet-class
init-param
param-nameconfiguration.file/param-name
param-valuec:\path\logging.cfg/param-value
/init-param
load-on-startup1/load-on-startup
/servlet

In our case, logging.cfg is a PropertyConfigurator file.


Have fun,


Yves Bossel




Re: log4j and ejb

2001-04-30 Thread Todd M Benge

Thanks for replies.  I don't think it's actually necessary to load it 
from a bean and would probably be better to use a servlet.

Todd

Fredrik Lindgren wrote:

 Is it necessary for you to load the configuration from an EJB?
 
 We use the DOMConfigurator by having a simple servlet load the
 configuration file as a resource. We set the servlet to load early at
 startup and we load the configuration in the servlet's init method to
 have the logging configured as early as possible. We use the servlet to
 reload the config after updates to the configuration as well. 
 
 This is what we do to load it:
 
   private void initLogging(){
   String configFileName;
 
   ServletContext ctx = getServletContext();
 try{
   DocumentBuilder builder =
 DocumentBuilderFactory.newInstance().newDocumentBuilder();
   Document document =
 builder.parse(ctx.getResourceAsStream(CONFIG_RESOURCE_PATH),CONFIG_RESOURCE_PATH);
   DOMConfigurator.configure(document.getDocumentElement());
   Category.getRoot().info(Log4J successfully initialized from  +
 CONFIG_RESOURCE_PATH);
 } catch (Exception err){
   log(error setting up logging config, err);
   BasicConfigurator.configure();
   Category.getRoot().warn(Log4J initialized using basic
 configurator);
 }
   }
 
 It works well for us for logging from both servlet and EJBs
 
 Fredrik Lindgren, Goyada AB
 
 Todd M Benge wrote:
 
 Hi,
 
 I'm trying to use log4j to log from an enterprise bean.  I've been able
 to get a bean to log to stdout using the BasicConfigurator but am not
 able to get it to log using either the DOMConfigurator or the
 PropertyConfigurator.  I believe Property and DOM configurators need a
 file to set up the appenders.  Has anybody been successful in using a
 configurator othere than the BasicConfigurator with a bean?  If so, how?
 
 Thanks,
 
 Todd
 





Re: log4j and ejb

2001-04-27 Thread Stan Ng

I pass in the Java property that points to the whatever configuration I want
at the time.  Usually I use the log4j.properties file with the console
appender  rolling file appender, slightly modified for my purposes.
Basically, the format of that file is covered under documentation at the
log4j website( http://jakarta.apache.org/log4j )

Returning to the topic at hand, my run_orion.bat has the following line:

java -Dlog4j.configuration=file:///orion/cfg/log4j.properties orion.jar


The property value I provide is just a URL to a local file.  I find it handy
to able to specify what configuration file I want while developing.  In
theory, the PropertyConfigurator checks a number of places, including the
classpath, for the log4j.properties file.  It doesn't seem to work for me,
but someone else on this list can probably help you out if you want to go
that route.

As far as I can tell, using log4j violates the letter of EJB spec, but not
the spirit.  Works just fine for me, so I'm going to go with the pragmatic
route and fix things later if need be.

hth...



- Original Message -
From: Todd M Benge [EMAIL PROTECTED]
To: Orion-Interest [EMAIL PROTECTED]
Sent: Friday, April 27, 2001 2:39 PM
Subject: log4j and ejb


 Hi,

 I'm trying to use log4j to log from an enterprise bean.  I've been able
 to get a bean to log to stdout using the BasicConfigurator but am not
 able to get it to log using either the DOMConfigurator or the
 PropertyConfigurator.  I believe Property and DOM configurators need a
 file to set up the appenders.  Has anybody been successful in using a
 configurator othere than the BasicConfigurator with a bean?  If so, how?

 Thanks,

 Todd






RE: log4j and ejb

2001-04-27 Thread Mike Cannon-Brookes

The problem with going this route (and it's what I do ;)) is that you only
have ONE log4j config for the whole server. Each app has the same logging
and you can't really separate them easily (without writing a long config
file that breaks up based on category).

-mike

 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED]]On Behalf Of Stan Ng
 Sent: Saturday, April 28, 2001 10:27 AM
 To: Orion-Interest
 Subject: Re: log4j and ejb


 I pass in the Java property that points to the whatever
 configuration I want
 at the time.  Usually I use the log4j.properties file with the console
 appender  rolling file appender, slightly modified for my purposes.
 Basically, the format of that file is covered under documentation at the
 log4j website( http://jakarta.apache.org/log4j )

 Returning to the topic at hand, my run_orion.bat has the following line:

 java -Dlog4j.configuration=file:///orion/cfg/log4j.properties orion.jar


 The property value I provide is just a URL to a local file.  I
 find it handy
 to able to specify what configuration file I want while developing.  In
 theory, the PropertyConfigurator checks a number of places, including the
 classpath, for the log4j.properties file.  It doesn't seem to work for me,
 but someone else on this list can probably help you out if you want to go
 that route.

 As far as I can tell, using log4j violates the letter of EJB spec, but not
 the spirit.  Works just fine for me, so I'm going to go with the pragmatic
 route and fix things later if need be.

 hth...



 - Original Message -
 From: Todd M Benge [EMAIL PROTECTED]
 To: Orion-Interest [EMAIL PROTECTED]
 Sent: Friday, April 27, 2001 2:39 PM
 Subject: log4j and ejb


  Hi,
 
  I'm trying to use log4j to log from an enterprise bean.  I've been able
  to get a bean to log to stdout using the BasicConfigurator but am not
  able to get it to log using either the DOMConfigurator or the
  PropertyConfigurator.  I believe Property and DOM configurators need a
  file to set up the appenders.  Has anybody been successful in using a
  configurator othere than the BasicConfigurator with a bean?  If so, how?
 
  Thanks,
 
  Todd