Ah! I knew there was a reason why I made my Loggers normal instance variables, I think this was probably it from when I was playing around with WebSphere.
Just declare your logger as private transient Logger logger = Logger.getLogger(...); and remember to reinitialise it in ejbActivate(). It may not be the prettiest solution but it works for me. If anyone has more elegant solutions ... Hope this helps Keith -----Original Message----- From: Lin, Bosheng [mailto:[EMAIL PROTECTED] Sent: 20 April 2004 13:35 To: 'Log4J Users List' Subject: RE: logging inside EJB even adding static final to logger public class LegacyServiceBean implements SessionBean{ private static final Logger logger = Logger.getLogger(LegacyServiceBean.class); } I still got the following warning when using IBM's AAT(version 4.00.032) to assemble the ear for OS390, J2EE1DOT2AppEJB.jar(Field: class$0, Class: LegacyServiceBean: CHKJ2200W: The field is static but not final. Read section 18.1.2 of the EJB 1.1 specification. Any idea? Thanks, Bosheng -----Original Message----- From: Robert Pepersack [mailto:[EMAIL PROTECTED] Sent: Monday, April 19, 2004 4:10 PM To: Log4J Users List Subject: Re: logging inside EJB Here's how I did it. // QueryBean.java package miaJ2ee.ejb.server; import java.util.ArrayList; import javax.ejb.SessionBean; import javax.ejb.SessionContext; import miaJ2ee.data.common.DataTransferObject; import miaJ2ee.ejb.client.QueryException; import miaJ2ee.dao.DataAccessObjectFactory; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; /** * QueryBean is the bean class for a stateless * session bean. */ public class QueryBean implements SessionBean { /** * Logger for this class. */ private static final Logger logger = Logger.getLogger("miaJ2ee.ejb.server.QueryBean"); /** * Info indicator for this class. */ private final boolean info = logger.isInfoEnabled(); public SessionContext context; public void ejbActivate(){} public void ejbPassivate(){} public void ejbRemove(){} public void ejbCreate() { PropertyConfigurator.configure("miaJ2ee.properties"); } public void setSessionContext(SessionContext ctx) { context = ctx; } /** * Get a DataTransferObject from the database. */ public DataTransferObject getObject(DataTransferObject data) throws QueryException { if (this.info) { logger.info("getObject() -- " + "Creating data access object by calling " + "DataAccessObjectFactory.createDao()..."); } try { return DataAccessObjectFactory.createDao(data.getType()).getObject(data); } catch (Exception e) { throw new QueryException(e); } } /** * Get an ArrayList of DataTransferObjects from the database. */ public ArrayList getObjectList(DataTransferObject data) throws QueryException { if (this.info) { logger.info("getObjectList() -- " + "Creating data access object by calling " + "DataAccessObjectFactory.createDao()..."); } try { return DataAccessObjectFactory.createDao(data.getType()).getObjectList(data); } catch (Exception e) { throw new QueryException(e); } } } My EJB container is Sybase EAServer, so I had to write a custom appender that writes to my server's log file. At 03:35 PM 04/19/2004 -0400, you wrote: >Hi, I am trying to put logger inside a stateless session bean, like > >public class LegacyServiceBean implements SessionBean{ > private Logger logger = >Logger.getLogger(LegacyServiceBean.class); >} > >When I use IBM's AAT(version 4.00.032) to assemble the ear for OS390, I >got the following warning, > >/J2EE1DOT2AppEJB.jar(Field: class$0, Class: >LegacyServiceBean: CHKJ2200W: The field is static but not final. Read >section 18.1.2 of the EJB 1.1 specification. > >I did not spend much on studying this, I am sure other peoples should >have encoutered this. > >What is the correct way to use log4j inside EJB? > >Thanks, > >Bosheng > >--------------------------------------------------------------------- >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] --------------------------------------------------------------------- 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]