6 Replies Latest reply on Apr 14, 2008 12:59 PM by gonzalad

    Better log handling during seam startup ?

    gonzalad Apprentice

      Hello,


      Just realized that Seam doesn't log when there's an error during startup (I'm using 2.0.0.GA).
      Seam just let the app server do the logging job.


      Could it be possible to add some log instructions ?


      For instance, in SeamListener :


      public void contextInitialized(ServletContextEvent event) {
        log.info( "Welcome to Seam " + Seam.getVersion() );
        try {
            ServletLifecycle.beginApplication( event.getServletContext() );
            new Initialization( event.getServletContext() ).create().init();
        } catch (RuntimeException err) {
            log.error("error while initializing Seam", err);
            throw err;
        } catch (Error err) {
            log.error("error while initializing Seam", err);
            throw err;
        }
      }
      



      My use case :
      I have at least 5 applications per VM. Each application has it's own log file.
      I would prefer to have all log info in each app log file rather than having to look at the VM stdout and guess from which application the error generated.



      Thanks for your help

        • 1. Re: Better log handling during seam startup ?
          Pete Muir Master

          Don't really understand your request.


          In the code you quote Seam is logging to either JDK logging or Log4j depending on which is installed.


          It's up to the logging provider/the app server to do any further work like splitting it out into application specific log files.

          • 2. Re: Better log handling during seam startup ?
            gonzalad Apprentice

            Really sorry, I didn't see your answer before.


            In fact, my problem is that Seam does not log errors on startup.


            Here's SeamListener 2.0.0.GA code :


               public void contextInitialized(ServletContextEvent event) 
               {
                  log.info( "Welcome to Seam " + Seam.getVersion() );
                  ServletLifecycle.beginApplication( event.getServletContext() );
                  new Initialization( event.getServletContext() ).create().init();
               }



            Would it be possible to modify SeamListener on order to do some error logging ? (like in the sample code I wrote in my first post).


            • 3. Re: Better log handling during seam startup ?
              Pete Muir Master

              I still don't understand what you mean? Any exceptions thrown by Seam at deployment will propagate up and the container will log them (thats the case in all the containers I've worked with - JBoss, Tomcat, Glassfish, WLS, WAS, OC4J).


              Log and rethrow is a particularly evil pattern as you end up with multiple points logging the same error - totally unnecessary if you have a well behaved container and logger.

              • 4. Re: Better log handling during seam startup ?
                gonzalad Apprentice


                Log and rethrow is a particularly evil pattern

                I see your point.


                I use Websphere. As you said, Websphere logs this kind of errors in stdout.



                My problem is more related to production habits in my company.
                One vm hosts more or less 5 applications. There's more than 50 vm in production.


                If we only rely on app server logging, each logging statement will be output to the same file (appserver's stdout), let's say
                /etc/websphere/logs/server1/SystemOut.log.


                It's really easier to have a specific file for each app.


                In order to do this, we usually parameter log4j in each application (having a custom log4j.xml in each application) to log to an application specific output directory.
                For instance :
                /etc/logs/sample-ear/sample.log (output from sample.ear)
                /etc/logs/hello-ear/hello.log (output from hello.ear)


                So, when we'll have 5 Seam powered apps per vm, we'll end up with the initialization errors of the 5 applications in the same log file (we cannot setup websphere to log in a different file for each application).


                It will be harder to dissociate logging output from application 1 from logging output from application 2.



                • 5. Re: Better log handling during seam startup ?
                  Pete Muir Master

                  I see your point, but this seems more of a websphere problem than a Seam problem - that WAS logs to STDOUT is very nasty!


                  The trouble with not propagating the exception (which is the other option) is that then the deployment won't fail.


                  Anyway, add this to platform interop in JIRA, and I'll consider options.