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
> 


Reply via email to