Hi Scott,
I have used log4j package with Stateless Session EJB.
Put the log4j config file int he weblogic home folder, the folder where
weblogic.properties is kept.
Use the following peice of code in ur EJB.


        //For logging locally using the log4j package
        public static Category catNs = null;
//Category.getInstance(NSBean.class.getName());


        /**
        * The static block  reads the inputs from :<p>
        * 1) nsConfig.txt - config for log4j
        * 2) notificationServer.properties - default parameters for NS like
protocol, from email address, etc.
        * <p> Thus it sets the global parameters required for the system.
        */


                static
                {
                        try
                        {
                                catNs =
Category.getInstance("net.datalinx.NotificationServer.statelessSession.NSBea
n");

                                Hashtable  env = new Hashtable();
                                env.put(Context.PROVIDER_URL, 
NSDetails.CONNECT_EJB_SERVER);
                                env.put(Context.INITIAL_CONTEXT_FACTORY,
weblogic.jndi.WLInitialContextFactory.class.getName());
                                Context ctx = new InitialContext(env);

                                T3ServicesDef t3services = (T3ServicesDef)
ctx.lookup("weblogic.common.T3Services");

                                /*
                                Do the following changes in the wweblogic.properties 
file
                                        
weblogic.io.fileSystem.nsFileSystem=c:/weblogic5.0
                                */
                                T3FileSystem t3fs = 
t3services.io().getFileSystem("nsFileSystem");

                                T3File propFile = t3fs.getFile(NSDetails.CONFIG_FILE);
                                T3File log4jFile = 
t3fs.getFile(NSDetails.LOG4J_CONFIG_FILE);

                                InputStream isNS = propFile.getFileInputStream();
                                InputStream isLog4j = log4jFile.getFileInputStream();

                                //For getting the config file - for log4j
                                
//PropertyConfigurator.configure(NSDetails.LOG4J_CONFIG_FILE);

                                //read the config file for the SMTP string
                                //Properties props = new Properties();
                                //FileInputStream istream = new 
FileInputStream(NSDetails.CONFIG_FILE);
                                Properties props = new Properties();
                                props.load(isNS);
                                isNS.close();

                                Properties propsLog4j = new Properties();
                                propsLog4j.load(isLog4j);
                                isLog4j.close();

                                PropertyConfigurator.configure(propsLog4j);

                                //set the defaults - smtp server url and the protocol
                                strProtocol = 
props.getProperty(NSDetails.PROTOCOL_KEY);
                                if(strProtocol==null || strProtocol.equals("null"))
                                {
                                        throw new InsufficientDataException("Error 
IDE001 :- The protocol
string (for eg. 'smtp') is not available in the properties file. ");
                                }
                                strProtocol = strProtocol.trim();

                                strSmtpHost = 
props.getProperty(NSDetails.SMTP_SERVER_KEY);
                                if(strSmtpHost==null || strSmtpHost.equals("null"))
                                {
                                        throw new InsufficientDataException("Error 
IDE002 :- The protocol
server URL (for eg. 'smtp.onsiteaccess.net') is not available in the
properties file. ");
                                }
                                strSmtpHost = strSmtpHost.trim();

                                strFrom = 
props.getProperty(NSDetails.DEFAULT_SENDER_KEY);
                                if(strFrom==null || strFrom.equals("null"))
                                {
                                        throw new InsufficientDataException("Error 
IDE003 :- The default
senders('from') email address is not available in the properties file.");
                                }
                                strFrom = strFrom.trim();

                                if(catNs.isEnabledFor(Priority.INFO))
                                {
                                        catNs.info("The protocol used by the 
Notification Server is : " +
strProtocol);
                                        catNs.info("The smtp url used to connect the 
SMTP Server will be : " +
strSmtpHost);
                                }

                        }
                        catch(Exception e)
                        {
                                //e.printStackTrace();
                                if(catNs.isEnabledFor(Priority.WARN))
                                {
                                        catNs.warn("Error E001 :- Problem in 
EmailNotification-setEnvironment()
: \n" + e.getMessage());
                                }
                                //throw new Exception("Error E001 :- Problem in
EmailNotification-setEnvironment(): \n" + e);
                        }
                }//end of static block




THis is working for me...Hope it works for u,..Hope u understand the above
coding..If any problem..let me know..
Bye and take care,
Jeet.




-----Original Message-----
From: L. Scott Emmons [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 26, 2001 4:53 PM
To: LOG4J Users Mailing List
Subject: Re: Log4j in J2ee


SCOTT FARQUHAR wrote:
> I am looking to use log4j in a j2ee application.  This question has more
to do with design
> patterns than log4j specifically, but I am hoping that someone will have
come across and
> solved something similar.
>
> However, for EJB's and my general classes - where should the
> PropertyConfigurator.configure() line go?  They are not guaranteed to run
in the same
> thread (i don't think).
>
> I'm sure that other people must have come across this problem (if indeed
it is a
> problem) - what should I do?

I did it via JNDI. Not sure if my implementation is ideal, but I wrote a
startup class that boots with the application server and reads the log4j
properties file and loads it up into JNDI.

Then, in my log4j wrappers I pull the properties from JNDI and pass it
to the PropertyConfigurator.

Seems to work pretty well, although there is a fairly large cost for
getting an initial JNDI Context which I haven't dealt with yet. I've
thought about writing a Context factory to create + cache Contexts in
advance, but I guess that's outside of this discussion...

Just one possible idea,
-Scott

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to