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 "Follender, Ivan (HBO)" <Iv...@hbo.com> on 2002/11/19 17:47:07 UTC

Log4J in EJBs

Hi-

I want to use Log4J in my EJBs.
The guidance I've been getting is that EJBs should not access system files
(e.g. log4j.properties).

Is there a recommended mechanism for configuring the LogFactory for EJBs?

Thanks,
ivan.

==============================================================================
This e-mail is intended only for the use of the addressees.  Any copying, forwarding, printing or other use of this e-mail by persons other than the addressees is not authorized.  This e-mail may contain information that is privileged, confidential and exempt from disclosure.  If you are not the intended recipient, please notify us immediately by return e-mail (including the original message in your reply) and then delete and discard all copies of the e-mail.  Thank you.




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Log4J in EJBs

Posted by Jacob Kjome <ho...@visi.com>.
Hello Ivan,

Well, you shouldn't use File IO in an EJB app because you can't
guarantee that the file can be read off the filesystem.  For instance,
the file could be served out of a jar file.  However as long as you
get an InputSream or URL of your properties or XML file, then you are
fine.  That means you can store your config file in a jar archive or
in a JNDI directory or wherever you want.  That said, I've not done
too much with EJB, but, in theory, there is no problem in reading your
config in EJB's.

Jake

Tuesday, November 19, 2002, 10:47:07 AM, you wrote:

FIH> Hi-

FIH> I want to use Log4J in my EJBs.
FIH> The guidance I've been getting is that EJBs should not access system files
FIH> (e.g. log4j.properties).

FIH> Is there a recommended mechanism for configuring the LogFactory for EJBs?

FIH> Thanks,
FIH> ivan.

FIH> ==============================================================================
FIH> This e-mail is intended only for the use of the addressees.  Any copying, forwarding, printing or other use of this e-mail by persons other than the addressees is not authorized.  This e-mail
FIH> may contain information that is privileged, confidential and exempt from disclosure.  If you are not the intended recipient, please notify us immediately by return e-mail (including the original
FIH> message in your reply) and then delete and discard all copies of the e-mail.  Thank you.




FIH> --
FIH> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
FIH> For additional commands, e-mail: <ma...@jakarta.apache.org>



-- 
Best regards,
 Jacob                            mailto:hoju@visi.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Log4J in EJBs

Posted by Christophe Marcourt <ch...@mondeca.com>.
Maybe you can configure your log4j with xml files and initialize the log4j
configurator with a ClassLoader as it is explained in the documentation.
I'm sure you need some servlets for your EJBs ?

Initialization servlet
It is also possible to use a special servlet for log4j initialization. Here
is an example,
package com.foo;[PARA][PARA]import
org.apache.log4j.PropertyConfigurator;[PARA]import
javax.servlet.http.HttpServlet;[PARA]import
javax.servlet.http.HttpServletRequest;[PARA]import
javax.servlet.http.HttpServletResponse;[PARA]import
java.io.PrintWriter;[PARA]import java.io.IOException;[PARA][PARA]public
class Log4jInit extends HttpServlet {[PARA][PARA]  public[PARA]  void init()
{[PARA]    String prefix =  getServletContext().getRealPath("/");[PARA]
String file = getInitParameter("log4j-init-file");[PARA]    // if the
log4j-init-file is not set, then no point in trying[PARA]    if(file !=
null) {[PARA]

PropertyConfigurator.configure(prefix+file);[PARA]    }[PARA]  }[PARA][PARA]
public[PARA]  void doGet(HttpServletRequest req, HttpServletResponse res)
{[PARA]  }[PARA]}
Define the following servlet in the web.xml file for your web-application.
  <servlet>[PARA]    <servlet-name>log4j-init</servlet-name>[PARA]
<servlet-class>com.foo.Log4jInit</servlet-class>[PARA][PARA]
<init-param>[PARA]      <param-name>log4j-init-file</param-name>[PARA]
<param-value>WEB-INF/classes/log4j.lcf</param-value>[PARA]
</init-param>[PARA][PARA]    <load-on-startup>1</load-on-startup>[PARA]
</servlet>
Writing an initialization servlet is the most flexible way for initializing
log4j. There are no constraints on the code you can place in the init()
method of the servlet.



Christophe Marcourt
Mondeca
Ingénieur R&D
3, Cité Nollez. 75018 Paris
Phone : +33 1 44 92 35 03
Mobile : +33 6 14 48 65 66
Fax : +33 1 44 92 02 59
http://www.mondeca.com/fr
ICQ : #119811844

-----Message d'origine-----
De : Follender, Ivan (HBO) [mailto:Ivan.Follender@hbo.com]
Envoyé : mardi 19 novembre 2002 17:47
À : 'log4j-user@jakarta.apache.org'
Objet : Log4J in EJBs

Hi-

I want to use Log4J in my EJBs.
The guidance I've been getting is that EJBs should not access system files
(e.g. log4j.properties).

Is there a recommended mechanism for configuring the LogFactory for EJBs?

Thanks,
ivan.

============================================================================
==
This e-mail is intended only for the use of the addressees.  Any copying,
forwarding, printing or other use of this e-mail by persons other than the
addressees is not authorized.  This e-mail may contain information that is
privileged, confidential and exempt from disclosure.  If you are not the
intended recipient, please notify us immediately by return e-mail (including
the original message in your reply) and then delete and discard all copies
of the e-mail.  Thank you.




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>