3 Replies Latest reply: Nov 12, 2013 7:35 PM by rp0428 RSS

    duplicate in log4j logging

    4thHorseman1985

      This is the sample log:

      Problem when performing SQL operations

      java.lang.NullPointerException

        at com.testing.Main.helloWorld(Main.java:35)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

        at java.lang.reflect.Method.invoke(Method.java:597)

        at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)

        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)

        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)

        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)

        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)

        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)

        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)

        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)

        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)

        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)

        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)

        at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)

        at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)

        at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)

        at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:183)

        at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3717)

        at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)

        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)

        at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)

        at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)

        at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)

        at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)

        at weblogic.work.ExecuteThread.execute(ExecuteThread.java:207)

        at weblogic.work.ExecuteThread.run(ExecuteThread.java:176)

      2013-11-08 14:08:00,828 [DEBUG] Resolving exception from handler [public void com.testing.Main.helloWorld(java.lang.String)]: java.lang.RuntimeException: java.lang.NullPointerException

      2013-11-08 14:08:00,841 [DEBUG] Resolving exception from handler [public void com.testing.Main.helloWorld(java.lang.String)]: java.lang.RuntimeException: java.lang.NullPointerException

      2013-11-08 14:08:00,841 [DEBUG] Resolving exception from handler [public void com.testing.Main.helloWorld(java.lang.String)]: java.lang.RuntimeException: java.lang.NullPointerException

      2013-11-08 14:08:00,847 [DEBUG] Could not complete request

      java.lang.RuntimeException: java.lang.NullPointerException

        at com.testing.MyLogger.error(MyLogger.java:24)

        at com.testing.Main.helloWorld(Main.java:35)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

        at java.lang.reflect.Method.invoke(Method.java:597)

        at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)

        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)

        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)

        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)

        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)

        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)

        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)

        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)

        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)

        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:839)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)

        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:821)

        at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)

        at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)

        at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)

        at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:184)

        at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3717)

        at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)

        at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)

        at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)

        at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)

        at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)

        at weblogic.work.ExecuteThread.run(ExecuteThread.java:176)

      Caused by: java.lang.NullPointerException

        at com.testing.Main.helloWorld(Main.java:35)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

        at java.lang.reflect.Method.invoke(Method.java:597)

        at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)

        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)

        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)

        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)

        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)

        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)

        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)

        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)

        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)

        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)

        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)

        at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)

        at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)

        at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)

        at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:183)

        at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3717)

        at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)

        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)

        at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)

        at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)

        at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)

        at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)

        at weblogic.work.ExecuteThread.execute(ExecuteThread.java:207)

        ... 1 more

       

      as you can see, the the same thing is being logged twice. the first log doesn't have the "caused by" part, where the second has that, but the ...1 more is very frustrating. I want a complete log.

      This is the config file:

      log4j.rootLogger = DEBUG, FILE 

      log4j.appender.FILE=org.apache.log4j.FileAppender 

      log4j.appender.FILE.File=c:/application.log 

      log4j.appender.FILE.layout=org.apache.log4j.PatternLayout 

      log4j.appender.FILE.layout.conversionPattern= %m%n


      I'm deploying this in weblogic. What am I doing wrong?

      thanks

        • 1. Re: duplicate in log4j logging
          jschellSomeoneStoleMyAlias

          Basically your code is logging it twice.  So to stop it you stop doing that.

           

          Your database layer is probably catching the exception, logging it, then wrapping it and throwing the new exception.  Which another layer captures and logs.

           

          Basic standard process - don't log exceptions that you rethrow.  Don't log exceptions that are wrapped in other exceptions (which are then thrown.)

          • 2. Re: duplicate in log4j logging
            4thHorseman1985

            so, what should I do? how do you usually log your exceptions when method A calls method B and both methods have exceptions in them? and what about the ...1 more issue? I want the complete stack trace.

            Thanks.

            • 3. Re: duplicate in log4j logging
              rp0428
              so, what should I do? how do you usually log your exceptions when method A calls method B and both methods have exceptions in them? and what about the ...1 more issue? I want the complete stack trace.

              jschell already answered that above.

               

              You can only control what YOUR code does. You can only control what other code does if that code ALLOWS you some control; for example via config files that allow you to specify the degree or type of logging.

               

              If your code calls a method in other code you have no way of knowing or controlling whether that other code logs certain exceptions or bubbles them up. And if that other code does trap an exception it may, or may not, log it, wrap it up, and then reraise the SAME exception or maybe raise a different one altogether. That other code might include TONS of stack trace or nothing at all.

               

              You can only control what YOUR code does. Follow jschell's advice above.