1 Reply Latest reply on Sep 26, 2003 2:01 AM by milowe

    custom EJB logging

    mgrove

      my application uses servlets, EJBs, and a resource adapter. i have custom logging needs for a single servlet, 2 EJBs (a SLSB wrapping a BMP EB), and a single resource adapter. our logging mechanism does not require/use log4j. there should be a total of 3 log files - one for the servlet, one for both EJBs, and one for the resource adapter. a single instance of our custom logger should be instantiated for each of the 3 components/files.

      currently my servlet instantiates its logger instance in init() after reading in all necessary properties from web.xml, while my resource adapter instantiates a static logger instance in ManagedConnectionFactory.createConnectionFactory, after getting the needed configuration parameters from its datasource file. in both of these cases there was a common entry point so it was relatively easy to construct the required logger and pass it to other components that needed it.

      what's the best way to install such a custom logger for use by my EJBs? at this time i'm not concerned with EJBs distributed across cluster nodes, so we can rely on the EJBs living in a single JVM. the best i can think of is to have a static variable in my SLSB that is initialized (with synchronization) in setSessionContext. i think that will take care of my SLSB...not sure how best to pass this to my EB. i suppose i could add a setEJBLogger method to my Home interface, and call it immediately after every lookup of the EB.

      any other ideas/suggestions are appreciated. in particular i'm not sure whether using synchronized in an EJB is legit.

        • 1. Re: custom EJB logging
          milowe

          Some of things you suggest are not good practice to ensure that the EJBs are portabel and compliant with any EJB container.

          An enterprise Bean must not use read/write static fields. Using read-only static fields is allowed. Therefore, it is recommended that all static fields in the enterprise bean class be declared as final.

          An enterprise Bean must not use thread synchronization primitives to synchronize execution of multiple instances.

          The easiest way to go would be to use log4j (even if you are not currently using it).

          /micke