Announcement Announcement Module
Collapse
No announcement yet.
Log4J + WebSphere config Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Log4J + WebSphere config

    If somebody could help me setup log4J for Spring properly in WebSphere, I would be grateful. I've been able to get log4J setup properly so that *my* code uses it, but I can't seem to control the amount of logging that Spring itself does. It appears to me that Spring is hooking into the standard WebSphere logging and so I don't know how to change the logging levels. Am I missing something really basic?

    I want to see some Spring/Acegi debugging output. Here's my log4j properties file:

    Code:
    log4j.rootLogger=DEBUG, stdout
    
    log4j.logger.org.springframework=DEBUG
    
    log4j.logger.org.acegisecurity=DEBUG
    
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n

    Here's some console output. My own code has a couple of logging messages at the bottom of this; you can see that the logging format is different. You can also see that log4J is getting initialized properly from log4j.properties.

    Code:
    [4/4/06 13:01:40:424 EDT] 00000020 ApplicationMg A   WSVR0200I: Starting application: SpringSample2.0EAR
    [4/4/06 13:01:40:611 EDT] 00000020 WebGroup      A   SRVE0169I: Loading Web Module: SpringSample2.0c.
    [4/4/06 13:01:40:814 EDT] 00000020 ContextLoader I   Root WebApplicationContext: initialization started
    [4/4/06 13:01:40:814 EDT] 00000020 WebApp        A   SRVE0180I: [SpringSample2.0c] [/SpringSample2.0c] [Servlet.LOG]: Loading Spring root WebApplicationContext
    [4/4/06 13:01:41:017 EDT] 00000020 XmlBeanDefini I   Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
    ...
    [4/4/06 13:01:42:158 EDT] 00000020 ContextLoader I   Root WebApplicationContext: initialization completed in 1344 ms
    [4/4/06 13:01:42:174 EDT] 00000020 WebApp        A   SRVE0180I: [SpringSample2.0c] [/SpringSample2.0c] [Servlet.LOG]: Set web app root system property: 'sample2.0c' = [C:\WebSphere\WorkSpace\normal.v6.0\SpringSample2.0c\WebContent]
    [4/4/06 13:01:42:220 EDT] 00000020 WebApp        A   SRVE0180I: [SpringSample2.0c] [/SpringSample2.0c] [Servlet.LOG]: Initializing Log4J from [C:\WebSphere\WorkSpace\normal.v6.0\SpringSample2.0c\WebContent\WEB-INF\log4j.properties]
    [4/4/06 13:01:42:564 EDT] 00000020 DispatcherSer I   Initializing servlet 'example'
    [4/4/06 13:01:42:627 EDT] 00000020 DispatcherSer I   FrameworkServlet 'example': initialization started
    [4/4/06 13:01:42:627 EDT] 00000020 WebApp        A   SRVE0180I: [SpringSample2.0c] [/SpringSample2.0c] [Servlet.LOG]: Loading WebApplicationContext for Spring FrameworkServlet 'example'
    [4/4/06 13:01:42:642 EDT] 00000020 XmlBeanDefini I   Loading XML bean definitions from ServletContext resource [/WEB-INF/example-servlet.xml]
    [4/4/06 13:01:42:955 EDT] 00000020 XmlWebApplica I   Bean factory for application context [WebApplicationContext for namespace 'example-servlet']: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [testMultiActionController,testMethodNameResolver,menuController,exceptionController,messageController,fileUploadController,viewResolver,messageSource,localeResolver,localeChangeInterceptor,multipartResolver,exceptionResolver,urlMapping]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [filterChainProxy,channelProcessingFilter,channelDecisionManager,secureChannelProcessor,insecureChannelProcessor,httpSessionContextIntegrationFilter,authenticationProcessingFilter,httpRequestAccessDecisionManager,roleVoter,authenticationDao,authenticationManager,daoAuthenticationProvider,filterInvocationInterceptor,exceptionTranslationFilter,authenticationProcessingFilterEntryPoint,rememberMeProcessingFilter,rememberMeServices,rememberMeAuthenticationProvider,anonymousProcessingFilter,anonymousAuthenticationProvider,switchUserProcessingFilter,concurrentSessionController,concurrentSessionFilter,sessionRegistry]; root of BeanFactory hierarchy
    ...
    [4/4/06 13:01:43:439 EDT] 00000020 DispatcherSer I   No HandlerAdapters found in servlet 'example': using default
    [4/4/06 13:01:43:470 EDT] 00000020 DispatcherSer I   Unable to locate RequestToViewNameTranslator with name 'viewNameTranslator': using default [org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator@2df20b6c]
    [4/4/06 13:01:43:470 EDT] 00000020 DispatcherSer I   FrameworkServlet 'example': initialization completed in 859 ms
    [4/4/06 13:01:43:486 EDT] 00000020 DispatcherSer I   Servlet 'example' configured successfully
    [4/4/06 13:01:43:486 EDT] 00000020 ServletWrappe A   SRVE0242I: [example]: Initialization successful.
    [4/4/06 13:01:43:486 EDT] 00000020 VirtualHost   I   SRVE0250I: Web Module SpringSample2.0c has been bound to default_host[*:80,*:443].
    [4/4/06 13:01:43:517 EDT] 00000020 ApplicationMg A   WSVR0221I: Application started: SpringSample2.0EAR
    [4/4/06 13:02:31:158 EDT] 00000040 ServletWrappe A   SRVE0242I: [/log.jsp]: Initialization successful.
    [4/4/06 13:02:31:236 EDT] 00000040 SystemOut     O 2006-04-04 13:02:31,236 DEBUG [com.ibm._jsp._log] - This is a LOG4J debug statement
    [4/4/06 13:02:31:236 EDT] 00000040 SystemOut     O 2006-04-04 13:02:31,236 WARN [com.ibm._jsp._log] - This is a LOG4J warn statement
    Here's my web.xml:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    	<display-name>
    	SpringSample2.0c</display-name>
    	
    	<!--
    	  - Key of the system property that should specify the root directory of this
    	  - web app. Applied by WebAppRootListener or Log4jConfigListener.
    	  -->
    	<context-param>
    		<param-name>webAppRootKey</param-name>
    		<param-value>sample2.0c</param-value>
    	</context-param>
    
    	<context-param>
    		<param-name>log4jConfigLocation</param-name>
    		<param-value>/WEB-INF/log4j.properties</param-value>
    	</context-param>
    
    	<context-param>
    		<description>
    		</description>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>/WEB-INF/applicationContext.xml</param-value>
    	</context-param>
    	<filter>
    		<description>
    		</description>
    		<display-name>
    		Acegi Filter Chain Proxy</display-name>
    		<filter-name>Acegi Filter Chain Proxy</filter-name>
    		<filter-class>org.acegisecurity.util.FilterToBeanProxy</filter-class>
    		<init-param>
    			<description>
    			</description>
    			<param-name>targetBean</param-name>
    			<param-value>filterChainProxy</param-value>
    		</init-param>
    	</filter>
    	<filter-mapping>
    		<filter-name>Acegi Filter Chain Proxy</filter-name>
    		<url-pattern>/*</url-pattern>
    	</filter-mapping>
    	<listener>
    		<description>
    		</description>
    		<display-name>
    		Spring Application Context Loader</display-name>
    		<listener-class>org.springframework.web.context.scope.RequestContextListener</listener-class>
    	</listener>
    	<listener>
    		<description>
    		</description>
    		<display-name>
    		ContextLoaderListener</display-name>
    		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>
    	<listener>
    		<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    	</listener>	
    	<listener>
    		<description>
    		Used by Acegi ConcurrentSessionFilter</description>
    		<display-name>
    		HttpSessionEventPublisher</display-name>
    		<listener-class>org.acegisecurity.ui.session.HttpSessionEventPublisher</listener-class>
    	</listener>
    	<servlet>
    		<description>
    		</description>
    		<display-name>
    		example</display-name>
    		<servlet-name>example</servlet-name>
    		<servlet-class>
    		org.springframework.web.servlet.DispatcherServlet</servlet-class>
    		<load-on-startup>1</load-on-startup>
    	</servlet>
    	<servlet-mapping>
    		<servlet-name>example</servlet-name>
    		<url-pattern>/example/*</url-pattern>
    	</servlet-mapping>
    	<welcome-file-list>
    		<welcome-file>index.html</welcome-file>
    		<welcome-file>index.jsp</welcome-file>
    	</welcome-file-list>
    </web-app>

  • #2
    JCL/Log4J logging with WebSphere v5/6

    Here's how I got Spring and Acegi to log using WebSphere v6 (the docs say it should work for v5 too).

    Setup Log4J initialization as I have above, which is how the Spring docs say you're supposed to set it up. The problem is that isn't enough with WebSphere.

    To make it work for WebSphere you MUST create a file called org.apache.commons.logging.LogFactory and place it in your META-INF/services directory. The contents of that file should read "org.apache.commons.logging.impl.LogFactoryImp l" (without the quotes).

    With that, you should get Spring/Acegi logging to pay attention to your log4j.properties file.

    Here's the WebSphere docs that I got that from (page 16, to be exact): http://www-1.ibm.com/support/docview...id=swg27004610

    Comment


    • #3
      The odessy never ends. I just upgraded the WebSphere server in my test environment where I had worked out the above from v6.0.0.0 to v6.0.2.5 and the logging stopped. I have a tech support request with IBM for an explanation/solution.

      Comment


      • #4
        Thanks for keeping this up to date... I will soon be facing the same issue.

        Comment


        • #5
          Great find! I gave up a while back because I couldn't find any useful information. Perhaps I shall revisit.

          Comment


          • #6
            Hi.
            I need help about using log4j with WAS 6. Can anyone explain the solution? Step by step. About the LogFactory class file we have to put under META-INF/services directory of the Web application: What the contents of the file must be? Can anyone send a prepared LogFactory file contents here?
            Please help.

            Comment


            • #7
              Originally posted by pea1 View Post
              The odessy never ends. I just upgraded the WebSphere server in my test environment where I had worked out the above from v6.0.0.0 to v6.0.2.5 and the logging stopped. I have a tech support request with IBM for an explanation/solution.
              Any solutions? I've got exact the same problem here.

              Thanks,

              Jeroen

              Comment


              • #8
                Sorry I didn't post the results of my IBM tech support request from this issue. Here is what I got from IBM:
                I reviewed the traces that you sent and it does appear that you are picking up the WebSphere version of commons-logging. WebSphere 6.0.2+ includes version 1.0.3 where as your app includes 1.0.4.

                Please change your WAR classloader policy to Parent_Last to allow your version to be picked up. See this link for details - http://publib.boulder.ibm.com/infoce...sload_web.html

                Here is some additional information on using Commons-Logging now that it is included with the WebSphere environment - http://publib.boulder.ibm.com/infoce..._jcl_conf.html
                This was so long ago that I forget if this fixed the problem for me. I assume it must have since I don't have any further email about that tech support request.

                Since then I have upgraded to 6.1 so I'm not running on 6.0.x currently. However the following might also be helpful; it is the configuration that I am using in 6.1 web applications. In my WEB-INF directory, I have a file called commons-logging.properties that contains the following:

                Code:
                priority=1
                org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.LogFactoryImpl
                I believe that the priority=1 tells the logging system to pay attention to the local configuration (in the web app). However, I don't know if all versions of commons-logging pay attention to that priority setting.

                Comment

                Working...
                X