Not too long ago, I developed in a WebSphere Application Server (WAS) environment that used EJBs and Servlets, and had a logging facility that was pretty good, but not up to the level of Log4J.
Mr. Wang's problem may indeed be that the EJB container does not have the Log4J configuration loaded. This is due to the fact that the EJB Container and the Servlet Container run in separate JVMs. When I developed for the WAS, we had to configure logging separately in the EJB and Servlet Containers (and again in any stand-alone Java Applications that we ran). Two possible methods of configuring Log4J in the EJB Container: 1. Create a Configuration Bean that configures Log4J from the config files, and execute this bean from a Configuration Servlet and from a Session Bean that is invoked by the Configuration Servlet. This method has the drawback of tightly coupling your EJB Container and Servlet Container, but is easy to set up. 2. Create the Configuration Bean and have a Static Initializer in each EJB that calls the Configuration Bean. This is done because we cannot be sure which EJB will be instantiated first, and therefore which will potentially need logging first. The Configuration Bean must now have some way of determining whether or not Log4J has already been configured (we made the Configuration Bean a Singleton with a boolean flag). Although its a bad idea for EJBs to access the OS file system, I don't think this restriction extends to all objects that happen to run within the EJB Container. Logging to files should still be OK because the EJBs are not accessing the File System, only the Log4J classes are. "Bellamy, Scot" <[EMAIL PROTECTED]> Sent by: [EMAIL PROTECTED] 04/03/02 03:33 PM Please respond to "Log4J Users List" To: "Log4J Users List" <[EMAIL PROTECTED]> cc: Subject: RE: Use Log4J with WebSphere It sounds like the instance of Log4J utilized by the EJB objects doesn't have the configuration loaded. I'm not familiar with Websphere so I think this is beyond my ability to help. Scot. -----Original Message----- From: Michael Wang (IT) [mailto:[EMAIL PROTECTED]] Sent: Wednesday, April 03, 2002 1:48 PM To: 'Log4J Users List' Subject: RE: Use Log4J with WebSphere thanks, but the point is that all java classes are running inside WebSphere. How come I get the output from normal java classes, but not from ejb bean classes? here is the way how I use Log4J. /** * Bean Implementation class of UtilityMgr Stateless Session EJB */ public class UtilityMgrBean implements SessionBean { /** * logger */ private static final LogHelper log = new LogHelper(UtilityMgrBean.class); .... .... if (log.isDebugEnabled()) log.debug("log is enabled"); } Then I have LogHelper class defined as below. Btw, I found also in EJB class, return category.isDebugEnabled() is not working. public class LogHelper implements { /** * Is the logging instance initialized. */ private static boolean initialized = false; /** * Logging Category */ private Category category = null; public LogHelper(Class component) { super(); // Initialize the logging system if required if (!initialized) init(); category = Category.getInstance(component); } public void debug(Object obj) { category.debug(obj); } public void debug(Object obj, Exception e) { category.debug(obj, e); } public void error(Object obj) { category.error(obj); } public void error(Object obj, Exception e) { category.error(obj, e); } public void info(Object obj) { category.info(obj); } public void info(Object obj, Exception e) { category.info(obj, e); } private static synchronized void init() { if (!initialized) { // Get the configuration from the property file PropertyConfigurator.configureAndWatch(MY_LOG_FILE, MY_REFRESH_RATE); initialized = true; } } public boolean isDebugEnabled() { // Somehow the following line is not working in EJB bean return category.isDebugEnabled(); } public boolean isInfoEnabled() { // Somehow the following line is not working in EJB bean return category.isInfoEnabled(); } public void warn(Object obj) { category.warn(obj); } public void warn(Object obj, Exception e) { category.warn(obj, e); } } Thanks. -----Original Message----- From: Bellamy, Scot [mailto:[EMAIL PROTECTED]] Sent: Wednesday, April 03, 2002 1:43 PM To: Log4J Users List Subject: RE: Use Log4J with WebSphere I don't believe that Log4J violates the EJB spec, unless you use it in such a way that it does. Section EJB.18.1.2 contains a list of programming restrictions for bean providers. In that section it states "An enterprise bean must not use the java.io package to attempt to access files and directories in the file system." I'm not sure if Webshpere allows violation of the specification or not. There are a couple of ways to work around this, however. 1. You can use the JDBC appender to write log information to a database. Since JDBC is part of the J2EE specification this is fully complient. 2. You can create a logging service that runs in a separate process and utilize JMS to send messages from your EJB beans to the logging service. Scot. -----Original Message----- From: Michael Wang (IT) [mailto:[EMAIL PROTECTED]] Sent: Wednesday, April 03, 2002 1:30 PM To: 'Log4J Users List' Subject: Use Log4J with WebSphere I'ved asked this question before. Now my problem is my Log4J works fine with any classes except EJB beans class. Any idea about how to configure WebSphere 4.0? I run my J2EE app within WebSphere for a while. Then I examine my log output file, it has all necessary output from any java classes except EJB beans. I vaguely remember awhile back somebody mentioned that Log4J violates EJB spec. Do I need to configure my WebSphere 4.0 to allow access to the file (the output is file). Thanks. -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>