7 Replies Latest reply: Mar 9, 2010 8:44 AM by e.gherardini RSS

    How to use log4j into weblogic 10.3

    e.gherardini
      Hi,
      I am migrating an enterprise application from JBoss 4.3 + JBossCache to WebLogic 10.3+Coherence.

      I am blocked since I can't get log4j to work inside WL.

      I enabled log4j inside the administration console, as stated in the user guide.

      Googling I've also found that I have to copy these 2 jars

      wllog4j.jar
      llog4j-1.2.14.jar

      inside my domain lib directory (that is C:\Oracle\Middleware\user_projects\domains\base_domain\lib), and I did it.

      Now where should I put the log4j.xml configuration file and how can I tell to WL to use that xml as log4j configuration ?


      To give you more information, my classes use log4j in this way:

      Logger log = Logger.getLogger(MyClass.class);

      And I am constantly getting this error:


      log4j:WARN No appenders could be found for logger (it.ltm.ejba.session.EjbAServiceBean).
      log4j:WARN Please initialize the log4j system properly.


      I hope someone can help me.

      I apologize for this stupid question, but really I didn't find a good guide/tutorial on the net.



      Thanks in advance.

      Edited by: e.gherardini on 3-mar-2010 3.16
        • 1. Re: How to use log4j into weblogic 10.3
          Jay SenSharma MiddlewareMagic
          Hi,

          Please refer to http://jaysensharma.wordpress.com/2010/03/03/log4j-at-application-level-in-weblogic/

          I have developed a Very Simple TestCase of Log4j to run in WebLogic...Please have a Look... (FileSize=      314 KB) http://www.4shared.com/file/233438339/c46d0ff/TestCase_Log4J.html




          Thanks
          Jay SenSharma
          http://jaysensharma.wordpress.com (WebLogic Wonders Are here)
          • 2. Re: How to use log4j into weblogic 10.3
            e.gherardini
            Hi Jay, thanks for helping me.

            In fact what I am trying to do is a server-wide log4j configuration.

            Your solution implies writing-deploying-maintaining 1 log4j configuration file for each application developed inside the application server.

            This is not what I want to do.


            Digging around WL 10.3 installation folders, I've found a log4j.properties file inside the medrec example application (C:\Oracle\Middleware\wlserver_10.3\samples\domains\medrec).

            It uses this properties file setting a startup parameter to the server (file setDomainEnv.cmd):
            set JAVA_PROPERTIES=%JAVA_PROPERTIES% -Dlog4j.configuration=file:%LOG4J_CONFIG_FILE%

            I would like to do the same starting the server from eclipse 3.5.

            I am working on this, I hope you can give some hints.

            Thanks a lot
            • 3. Re: How to use log4j into weblogic 10.3
              e.gherardini
              Ok,I got it!

              To use log4j inside weblogic I added a log4j env variable inside the setDomainEnv.cmd script.

              This is an example:
              @REM aggiunta da EMANUELE per log4j
              set LOG4J_CONFIG_FILE=C:\Oracle\Middleware\user_projects\domains\base_domain\config\log4j.xml
              for %%i in ("%LOG4J_CONFIG_FILE%") do set LOG4J_CONFIG_FILE=%%~fsi

              and now log4j works.


              Is this "right solution" ? Or exists a better way to accomplish my aim?

              Thanks.
              • 4. Re: How to use log4j into weblogic 10.3
                Jay SenSharma MiddlewareMagic
                Yes, At server level if we want to enable the Log4j then that is the right way. If we want the WebLoguic Server Logging also should happen in Log4j fashion then additionally we need to login to AdminConsole--->DomainName (TestDomain)--->Configuration (Tab)---> Logging (SubTab)---> Advanced options (bottom of the page)---> Logging implementation: (we need to select it to Log4j) default logging implementation is JDK.


                I do it in a different way ... I just put the Log4j.properties/xml file in the Server classpath and it gets picked up.

                Edited by: Jay SenSharma on Mar 3, 2010 9:38 PM
                • 5. Re: How to use log4j into weblogic 10.3
                  e.gherardini
                  >
                  I do it in a different way ... I just put the Log4j.properties/xml file in the Server classpath and it gets picked up.


                  If I understood correctly, you configure the Environment Variable as I did, but instead of putting the entire "log4j.xml" path inside the variable, you put only the name of the log4j configuration file, having the file in the server classpath. Right !?

                  To do it in your way, where should I put the configuration file ? Inside a shared library deployed in the server ?
                  Or in some specific folder, so the server will "auto-magically" load that file!?

                  Thanks again for your time Jay.
                  • 6. Re: How to use log4j into weblogic 10.3
                    Jay SenSharma MiddlewareMagic
                    I add the following JAVA_OPTION in startWebLogic.sh -Dlog4j.Configuration=Mylog4j.xml and add the "Mylog4j.xml" in the Server Classpath


                    Example:
                    SAVE_JAVA_OPTIONS="${JAVA_OPTIONS}" -Dlog4j.Configuration=Mylog4j.xml
                    SAVE_CLASSPATH="${CLASSPATH}:/apps/myfiles/MyLog4j.xml"
                    • 7. Re: How to use log4j into weblogic 10.3
                      e.gherardini
                      Ok, so finally this is what I've done to configure log4j:

                      I've only modified the scritp startWebLogic.cmd:

                      set LOG4J_CONFIG_FILE=log4j.xml
                      set SAVE_JAVA_OPTIONS=%JAVA_OPTIONS% -Dlog4j.configuration=%LOG4J_CONFIG_FILE%

                      @REM set SAVE_CLASSPATH=%CLASSPATH%
                      set SAVE_CLASSPATH=%CLASSPATH%;C:\Oracle\Middleware\user_projects\domains\base_domain\config

                      In this way I've put all the config folder inside the classpath, and I can use it in future to hold other libraries configuration files (for example oracle coherence config).