Monday, March 29, 2010

Grails enable access log for embedded Jetty server

Create the file jetty-env.xml in /web-app/WEB-INF folder.
http://communitymapbuilder.org/display/JETTY/jetty-env.xml: says this xml is used for JNDI config.

http://docs.codehaus.org/display/JETTY/Logging+Requests :
Use the lower example.
<?xml version="1.0"?>
          <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD
Configure//EN"
               "http://jetty.mortbay.org/configure.dtd">
<Configure class="org.mortbay.jetty.webapp.WebAppContext">              
<Call name="addHandler">
    <Arg>
    <New class="org.mortbay.jetty.handler.RequestLogHandler">
      <Set name="requestLog">
        <New id="RequestLogImpl" class="org.mortbay.jetty.NCSARequestLog">
          <Arg><SystemProperty name="jetty.logs" default="./logs"/>/yyyy_mm_dd.request.log</Arg>
          <Set name="retainDays">90</Set>
          <Set name="append">true</Set>
          <Set name="extended">false</Set>
          <Set name="LogTimeZone">GMT</Set>
        </New>
      </Set>
    </New>
    </Arg>
  </Call>
</Configure>

Using the upper example:
<?xml version="1.0"?>
          <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD
Configure//EN"
               "http://jetty.mortbay.org/configure.dtd">
<Configure class="org.mortbay.jetty.webapp.WebAppContext">              
<Set name="handler">
      <New id="Handlers" class="org.mortbay.jetty.handler.HandlerCollection">
        <Set name="handlers">
         <Array type="org.mortbay.jetty.Handler">
           <Item>
             <New id="Contexts" class="org.mortbay.jetty.handler.ContextHandlerCollection"/>
           </Item>
           <Item>
             <New id="DefaultHandler" class="org.mortbay.jetty.handler.DefaultHandler"/>
           </Item>
           <Item>
             <New id="RequestLog" class="org.mortbay.jetty.handler.RequestLogHandler"/>
           </Item>
         </Array>
        </Set>
      </New>
    </Set>


    <Ref id="RequestLog">
      <Set name="requestLog">
        <New id="RequestLogImpl" class="org.mortbay.jetty.NCSARequestLog">
          <Arg><SystemProperty name="jetty.logs" default="./logs"/>/yyyy_mm_dd.request.log</Arg>
          <Set name="retainDays">90</Set>
          <Set name="append">true</Set>
          <Set name="extended">false</Set>
          <Set name="LogTimeZone">GMT</Set>
        </New>
      </Set>
    </Ref>
</Configure>

Causes the logging to be good but application initialization remians incomplete. If you look at the console logs, following steps are missing:

17:06:36,064 INFO  [/YourGrailsAppName][] Initializing Spring FrameworkServlet 'grails'
17:06:36,064 INFO  [GrailsDispatcherServlet][] FrameworkServlet 'grails': initia
lization started
17:06:36,189 INFO  [GrailsDispatcherServlet][] Using MultipartResolver [org.code
haus.groovy.grails.web.multipart.ContentLengthAwareCommonsMultipartResolver@c244
96]
17:06:36,189 INFO  [GrailsDispatcherServlet][] FrameworkServlet 'grails': initia
lization completed in 125 ms

Eventually an access log file named for eg. 2009_05_20.request.log is created in your application's logs folder.

No comments:

Post a Comment