Using Log4j in WebSphere v6.1 - Websphere

This is a discussion on Using Log4j in WebSphere v6.1 - Websphere ; Anyone here can help me on using Log4j in Websphere? I use RAD7 (run time environment WebSphere v6.1) to develop a Enterprice Application myProject. myProject includes a web project myWeb, an EJB project myEJB. I also created a java project ...

+ Reply to Thread
Results 1 to 15 of 15

Thread: Using Log4j in WebSphere v6.1

  1. Using Log4j in WebSphere v6.1

    Anyone here can help me on using Log4j in Websphere?

    I use RAD7 (run time environment WebSphere v6.1) to develop a Enterprice Application myProject. myProject includes a web project myWeb, an EJB project myEJB. I also created a java project commons-logging that imported commons-logging-1.1.1.jar and common-logging.properties file.

    this is my logging.properties content:

    priority=1
    org.apache.commons.logging.LogFactory=org.apache.c ommons.logging.impl.Log4jFactory

    log4j-1.2.15.jar and log4j.properties were imported into root directory of myProject. the log4j.properties contains following lines:


    log4j.rootLogger=DEBUG,myAppender

    log4j.appender.myAppender=org.apache.log4j.DailyRo llingFileAppender
    log4j.appender.myAppender.File=logs/myIcrLog.log
    log4j.appender.myAppender.ImmediateFlush=true
    log4j.appender.myAppender.DatePattern='.'yyyy-MM-dd

    log4j.appender.myAppender.layout=org.apache.log4j. PatternLayout
    log4j.appender.myAppender.layout.ConversionPattern =%d [%-5p] (%t) %c: %m%n

    In the servlet, I use following statements to call log4j:

    Logger log = Logger.getLogger("myLogger");
    log.info("start servlet logging...");


    I got the error:


    [9/22/08 11:07:28:670 CDT] 0000002f ServletWrappe I SRVE0242I: [myProject] [/myWeb] [/myJsp.jsp]: Initialization successful.
    [9/22/08 11:07:36:982 CDT] 0000002f ServletWrappe I SRVE0242I: [myProject] [/myWeb] [myServlet]: Initialization successful.
    [9/22/08 11:07:36:992 CDT] 0000002f SystemOut O servlet started
    [9/22/08 11:07:37:132 CDT] 0000002f SecurityManag W SECJ0314W: Current Java 2 Security policy reported a potential violation of Java 2 Security Permission. Please refer to InfoCenter for further information.

    Permission:

    getClassLoader : Access denied (java.lang.RuntimePermission getClassLoader)


    Code:

    org.apache.log4j.helpers.Loader in {file:/C:/Documents and Settings/zs4352/IBM/rationalsdp7.0/workspace/myProject/log4j-1.2.15.jar}



    Stack Trace:

    java.security.AccessControlException: Access denied (java.lang.RuntimePermission getClassLoader)
    at java.security.AccessController.checkPermission(Acc essController.java:104)
    at java.lang.SecurityManager.checkPermission(Security Manager.java:547)
    at com.ibm.ws.security.core.SecurityManager.checkPerm ission(SecurityManager.java:189)
    at java.lang.Thread.getContextClassLoader(Thread.java :484)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:64)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:615)
    at org.apache.log4j.helpers.Loader.getTCL(Loader.java :155)
    at org.apache.log4j.helpers.Loader.getResource(Loader .java:93)
    at org.apache.log4j.LogManager.(LogManager.java:105)
    at java.lang.J9VMInternals.initializeImpl(Native Method)
    at java.lang.J9VMInternals.initialize(J9VMInternals.j ava:177)
    at org.apache.log4j.Logger.getLogger(Logger.java:105)
    at myWeb.myServlet.doPost(myServlet.java:42)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:763)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:856)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.ser vice(ServletWrapper.java:966)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.han dleRequest(ServletWrapper.java:478)
    at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.h andleRequest(ServletWrapper.java:463)
    at com.ibm.ws.webcontainer.webapp.WebApp.handleReques t(WebApp.java:3129)
    at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequ est(WebGroup.java:238)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest (WebContainer.java:811)
    at com.ibm.ws.wswebcontainer.WebContainer.handleReque st(WebContainer.java:1433)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.read y(WCChannelLink.java:93)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLi nk.handleDiscrimination(HttpInboundLink.java:465)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLi nk.handleNewInformation(HttpInboundLink.java:394)
    at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCa llback.complete(HttpICLReadCallback.java:102)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListe ner.futureCompleted(AioReadCompletionListener.java :152)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallbac k(AbstractAsyncFuture.java:213)
    at com.ibm.io.async.AbstractAsyncFuture.fireCompletio nActions(AbstractAsyncFuture.java:195)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture .java:136)
    at com.ibm.io.async.ResultHandler.complete(ResultHand ler.java:194)
    at com.ibm.io.async.ResultHandler.runEventProcessingL oop(ResultHandler.java:741)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler .java:863)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.j ava:1510)


    Code Base Location:


    [9/22/08 11:07:37:192 CDT] 0000002f SecurityManag W SECJ0314W: Current Java 2 Security policy reported a potential violation of Java 2 Security Permission. Please refer to InfoCenter for further information.

    Permission:

    getClassLoader : Access denied (java.lang.RuntimePermission getClassLoader)


    Code:

    org.apache.log4j.helpers.Loader in {file:/C:/Documents and Settings/zs4352/IBM/rationalsdp7.0/workspace/myProject/log4j-1.2.15.jar}



    Stack Trace:

    ...............................


    By the way, I put log4j.jar and log4j.properties in classpath, and make log4j.jar available to myWeb and myEJB project.

    any one know how to fix it? Thanks.

  2. Re: Using Log4j in WebSphere v6.1

    zs4352@att.com wrote:
    > Anyone here can help me on using Log4j in Websphere?
    >
    > I use RAD7 (run time environment WebSphere v6.1) to develop a Enterprice Application myProject. myProject includes a web project myWeb, an EJB project myEJB. I also created a java project commons-logging that imported commons-logging-1.1.1.jar and common-logging.properties file.
    >
    > this is my logging.properties content:
    >
    > priority=1
    > org.apache.commons.logging.LogFactory=org.apache.c ommons.logging.impl.Log4jFactory
    >
    > log4j-1.2.15.jar and log4j.properties were imported into root directory of myProject. the log4j.properties contains following lines:
    >
    >
    > log4j.rootLogger=DEBUG,myAppender
    >
    > log4j.appender.myAppender=org.apache.log4j.DailyRo llingFileAppender
    > log4j.appender.myAppender.File=logs/myIcrLog.log
    > log4j.appender.myAppender.ImmediateFlush=true
    > log4j.appender.myAppender.DatePattern='.'yyyy-MM-dd
    >
    > log4j.appender.myAppender.layout=org.apache.log4j. PatternLayout
    > log4j.appender.myAppender.layout.ConversionPattern =%d [%-5p] (%t) %c: %m%n
    >
    > In the servlet, I use following statements to call log4j:
    >
    > Logger log = Logger.getLogger("myLogger");
    > log.info("start servlet logging...");
    >
    >
    > I got the error:
    >
    >
    > [9/22/08 11:07:28:670 CDT] 0000002f ServletWrappe I SRVE0242I: [myProject] [/myWeb] [/myJsp.jsp]: Initialization successful.
    > [9/22/08 11:07:36:982 CDT] 0000002f ServletWrappe I SRVE0242I: [myProject] [/myWeb] [myServlet]: Initialization successful.
    > [9/22/08 11:07:36:992 CDT] 0000002f SystemOut O servlet started
    > [9/22/08 11:07:37:132 CDT] 0000002f SecurityManag W SECJ0314W: Current Java 2 Security policy reported a potential violation of Java 2 Security Permission. Please refer to InfoCenter for further information.
    >
    > Permission:
    >
    > getClassLoader : Access denied (java.lang.RuntimePermission getClassLoader)
    >
    >
    > Code:
    >
    > org.apache.log4j.helpers.Loader in {file:/C:/Documents and Settings/zs4352/IBM/rationalsdp7.0/workspace/myProject/log4j-1.2.15.jar}
    >
    >
    >
    > Stack Trace:
    >
    > java.security.AccessControlException: Access denied (java.lang.RuntimePermission getClassLoader)
    > at java.security.AccessController.checkPermission(Acc essController.java:104)
    > at java.lang.SecurityManager.checkPermission(Security Manager.java:547)
    > at com.ibm.ws.security.core.SecurityManager.checkPerm ission(SecurityManager.java:189)
    > at java.lang.Thread.getContextClassLoader(Thread.java :484)
    > at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    > at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:64)
    > at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:43)
    > at java.lang.reflect.Method.invoke(Method.java:615)
    > at org.apache.log4j.helpers.Loader.getTCL(Loader.java :155)
    > at org.apache.log4j.helpers.Loader.getResource(Loader .java:93)
    > at org.apache.log4j.LogManager.(LogManager.java:105)
    > at java.lang.J9VMInternals.initializeImpl(Native Method)
    > at java.lang.J9VMInternals.initialize(J9VMInternals.j ava:177)
    > at org.apache.log4j.Logger.getLogger(Logger.java:105)
    > at myWeb.myServlet.doPost(myServlet.java:42)
    > at javax.servlet.http.HttpServlet.service(HttpServlet .java:763)
    > at javax.servlet.http.HttpServlet.service(HttpServlet .java:856)
    > at com.ibm.ws.webcontainer.servlet.ServletWrapper.ser vice(ServletWrapper.java:966)
    > at com.ibm.ws.webcontainer.servlet.ServletWrapper.han dleRequest(ServletWrapper.java:478)
    > at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.h andleRequest(ServletWrapper.java:463)
    > at com.ibm.ws.webcontainer.webapp.WebApp.handleReques t(WebApp.java:3129)
    > at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequ est(WebGroup.java:238)
    > at com.ibm.ws.webcontainer.WebContainer.handleRequest (WebContainer.java:811)
    > at com.ibm.ws.wswebcontainer.WebContainer.handleReque st(WebContainer.java:1433)
    > at com.ibm.ws.webcontainer.channel.WCChannelLink.read y(WCChannelLink.java:93)
    > at com.ibm.ws.http.channel.inbound.impl.HttpInboundLi nk.handleDiscrimination(HttpInboundLink.java:465)
    > at com.ibm.ws.http.channel.inbound.impl.HttpInboundLi nk.handleNewInformation(HttpInboundLink.java:394)
    > at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCa llback.complete(HttpICLReadCallback.java:102)
    > at com.ibm.ws.tcp.channel.impl.AioReadCompletionListe ner.futureCompleted(AioReadCompletionListener.java :152)
    > at com.ibm.io.async.AbstractAsyncFuture.invokeCallbac k(AbstractAsyncFuture.java:213)
    > at com.ibm.io.async.AbstractAsyncFuture.fireCompletio nActions(AbstractAsyncFuture.java:195)
    > at com.ibm.io.async.AsyncFuture.completed(AsyncFuture .java:136)
    > at com.ibm.io.async.ResultHandler.complete(ResultHand ler.java:194)
    > at com.ibm.io.async.ResultHandler.runEventProcessingL oop(ResultHandler.java:741)
    > at com.ibm.io.async.ResultHandler$2.run(ResultHandler .java:863)
    > at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.j ava:1510)
    >
    >
    > Code Base Location:
    >
    >
    > [9/22/08 11:07:37:192 CDT] 0000002f SecurityManag W SECJ0314W: Current Java 2 Security policy reported a potential violation of Java 2 Security Permission. Please refer to InfoCenter for further information.
    >
    > Permission:
    >
    > getClassLoader : Access denied (java.lang.RuntimePermission getClassLoader)
    >
    >
    > Code:
    >
    > org.apache.log4j.helpers.Loader in {file:/C:/Documents and Settings/zs4352/IBM/rationalsdp7.0/workspace/myProject/log4j-1.2.15.jar}
    >
    >
    >
    > Stack Trace:
    >
    > ..............................
    >
    >
    > By the way, I put log4j.jar and log4j.properties in classpath, and make log4j.jar available to myWeb and myEJB project.
    >
    > any one know how to fix it? Thanks.
    >

    These are the relevant lines:
    -----------------------------

    [9/22/08 11:07:37:192 CDT] 0000002f SecurityManag W SECJ0314W: Current Java 2 Security policy reported a potential violation of Java 2 Security Permission. Please refer to InfoCenter for further information.

    Permission:

    getClassLoader : Access denied (java.lang.RuntimePermission getClassLoader)

    ------------------------------

    As the error message says, look in the docs for further information. You've turned on Java 2 Security, and you'll need to modify .policy files in order to allow log4j to access the classes it needs.

    Ken

  3. Re: Using Log4j in WebSphere v6.1

    Ken Hygh wrote:

    > ------------------------------
    >
    > As the error message says, look in the docs for further information.
    > You've turned on Java 2 Security, and you'll need to modify .policy
    > files in order to allow log4j to access the classes it needs.
    >
    > Ken


    Ot turn off Java 2 security, which in most cases adds overhead but no
    value.

  4. Re: Using Log4j in WebSphere v6.1

    This issue look like caused when Java security enabled, the application does not have the necessary privilege to access the classloader.
    Would you try to turn off Java security and restart application, then verify that is work or not firstly.

  5. Re: Using Log4j in WebSphere v6.1

    Classpath Variables
    then add a new variable LOG4J_CONFIG, its value is full path in which my log4j.properties located.

    It did not work.

    It definitely is a classpath problem, however I tried everything it simply did not work.

    Anyone can help me?

    Thanks in advance.

  6. Re: Using Log4j in WebSphere v6.1

    zs4352@att.com wrote:
    > Classpath Variables
    > then add a new variable LOG4J_CONFIG, its value is full path in which my log4j.properties located.
    >
    > It did not work.
    >
    > It definitely is a classpath problem, however I tried everything it simply did not work.
    >
    > Anyone can help me?
    >
    > Thanks in advance.


    Did you turn off Java 2 security yet?

  7. Re: Using Log4j in WebSphere v6.1

    Try putting your log4j.properties file directly under the source folder (ejbModule is the default name for the source folder) for your EJB project. As long as your web project references your EJB project, this will allow the log4j.properties file to be loaded from your web project, as well.

  8. Re: Using Log4j in WebSphere v6.1

    BSteinbach, thank you for your help. It works. However, the project I am working on includes several EJB, Web, Webservice and Java Util projects. I am looking for a method that put log4j.properties in one single place, say root directory of EAR project so that every component can use it. keep one single log4j.properties file make maintenance easier.

    several articles mentioned that put log4j.properties under EAR root works for WebSphere v5, but it did not work for WebSphere 6 in my test. I thought I did something wrong!

    Do you have any opinion about it?

  9. Re: Using Log4j in WebSphere v6.1

    You may need to update the MANIFEST.MF files for your various modules to include the classpath from the ear.

    Ken

  10. Re: Using Log4j in WebSphere v6.1

    Ken,

    Only .jar file could be added to MANIFEST.MF file classpath. How do I add log4j.properties to it?

  11. Re: Using Log4j in WebSphere v6.1

    Actually on thinking more about your problem, log4j.properties needs to be global to the JVM, not the application. Drop it into \lib\ext.

    Ken

  12. Re: Using Log4j in WebSphere v6.1

    Ken,

    Could you explain how to drop log4j.properties into lib\ext in RAD7 development environment?

    And I think that log4j.properties should not be global to JVM, because every application need different log4j configuration.

    Thanks

  13. Re: Using Log4j in WebSphere v6.1

    Put the log4j.properties file directly under the Source folder for a plain Java Project. Then add that java project as a utility jar to all the EAR files you need it in. You will need to make sure it is added to the MANIFEST.MF of those projects, as well.

  14. Re: Using Log4j in WebSphere v6.1

    BSteinbach,

    Thank you very much. That works well.

    Thanks again.

  15. Re: Using Log4j in WebSphere v6.1

    Hi All,

    I had a similar issue with websphere v61, but when i checked in application binaries i found no file by name log4j.properties. I am basically websphere admin and doesn't have that much idea logger api's , what should be my next step.

    But i am able to see log4j.xml and log4jconfig.xml files in the application binaries.

    Please suggest on this.

    Thanks.

+ Reply to Thread