5 Replies Latest reply on Mar 30, 2004 4:35 AM by ahardy66

    Logging stacktraces from tomcat

    ahardy66 Novice

      When I get an exception thrown in JBoss, the stacktrace comes out to the log / console as it is.

      When I do that in embedded tomcat, JBoss or Log4J or something preceeds each line of the stacktrace with a logging format, e.g.

      17:50:08,297 INFO [STDOUT] java.lang.Exception: blah blah
      17:50:08,297 INFO [STDOUT] at blah1
      17:50:08,297 INFO [STDOUT] at blah2

      Can I configure log4j not to do this? I have trained my eye (and others I work with have too) to spot original stack traces from 100 yards, whereas the 'wrapped' stacktrace is much less likely to stand out.


        • 1. Re: Logging stacktraces from tomcat
          Scott Stark Master

          This means the code generating the printStackTrace() output is doing a System.out.println() for everyline in the trace. It needs to be emitted as a single string in one System.out/err println.

          • 2. Re: Logging stacktraces from tomcat
            ahardy66 Novice

            Any idea why it would be doing that? It is just my normal error handling in my servlet. Running under standalone tomcat, exception.printStackTrace() has never done this.

            The standard-out from JBoss-tomcat is obviously being funnelled through a log4j logger somehow - hence the INFO level - but which logger would it be?

            If there is no other option, could I configure a different formatter for it?

            Also of course, JBoss shouldn't be assigning it a log4j level at all really - if that is possible.


            • 3. Re: Logging stacktraces from tomcat
              ahardy66 Novice

              I don't know what it is that is causing log4j to wrap the stacktraces from tomcat, presumably it's something in the tomcat - jboss integration. I'd love to know - anyone from JBoss?

              Anyway the solution is to adjust the log4j configuration. It means taking the appenders off the root category and putting them individually on the subcategories, including 2 categories called STDOUT and STDERR.

              I defined a basic layout pattern for STDOUT and STDERR so that there is no extraneous output attached to each statement.

              You have to take the console appender off the root category though, which is a bit of a pain, so that STDOUT and STDERR don't print twice.

              Creating an "org" category and a "tomcat.localhost" category is a suitable way of assigning an appender to all other categories.

              • 4. Re: Logging stacktraces from tomcat
                Scott Stark Master

                We redirect System.out, System.err to a log4j appender. If you don't want that behavior set the org.jboss.logging.Log4jService.catchSystemOut and org.jboss.logging.Log4jService.catchSystemErr system properties to false.