~ factorize the RequestLogger
authorAlexandre Bertails <bertails@w3.org>
Wed, 24 Aug 2011 14:27:37 -0400
changeset 62 7cf163bf2865
parent 61 95ad8e0f7ae0
child 63 6ff1023ed3dd
~ factorize the RequestLogger
src/main/scala/Main.scala
src/main/scala/Util.scala
--- a/src/main/scala/Main.scala	Wed Aug 24 14:18:55 2011 -0400
+++ b/src/main/scala/Main.scala	Wed Aug 24 14:27:37 2011 -0400
@@ -63,6 +63,9 @@
 
 }
 
+import VirtualTrainerApp._
+import org.w3.virtualtrainer.util.RequestLogger
+
 object VirtualTrainerAppMain {
 
   val logger:Logger = LoggerFactory.getLogger(this.getClass)
@@ -76,23 +79,9 @@
 
     val port = args.toList.headOption map { _.toInt } getOrElse 2719
     
-    import javax.servlet._
-    import javax.servlet.http._
-    import VirtualTrainerApp._
-    
-    unfiltered.jetty.Http(port).filter {
-      new Filter {
-        def destroy():Unit = ()
-        def doFilter(request:ServletRequest, response:ServletResponse, chain:FilterChain):Unit = {
-          val r:HttpServletRequest = request.asInstanceOf[HttpServletRequest]
-   		  val method = r.getMethod
-          val uri = r.getRequestURI 
-          logger.info("%s %s" format (method, uri))
-          chain.doFilter(request, response)
-        }
-        def init(filterConfig:FilterConfig):Unit = ()
-      }
-    }.context("/scripts"){ ctx:ContextBuilder =>
+    unfiltered.jetty.Http(port)
+    .filter(new RequestLogger {})
+    .context("/scripts"){ ctx:ContextBuilder =>
       ctx.resources(fromClasspath("scripts/").toURI.toURL)
     }.context("/styles"){ ctx:ContextBuilder =>
       ctx.resources(fromClasspath("styles/").toURI.toURL)
--- a/src/main/scala/Util.scala	Wed Aug 24 14:18:55 2011 -0400
+++ b/src/main/scala/Util.scala	Wed Aug 24 14:27:37 2011 -0400
@@ -59,4 +59,24 @@
     dir
   }
   
+}
+
+import javax.servlet._
+import javax.servlet.http._
+
+trait RequestLogger extends Filter {
+  
+  val logger:Logger = LoggerFactory.getLogger(this.getClass)
+  
+  def destroy():Unit = ()
+
+  def doFilter(request:ServletRequest, response:ServletResponse, chain:FilterChain):Unit = {
+    val r:HttpServletRequest = request.asInstanceOf[HttpServletRequest]
+    val method = r.getMethod
+    val uri = r.getRequestURI 
+    logger.info("%s %s" format (method, uri))
+    chain.doFilter(request, response)
+  }
+
+  def init(filterConfig:FilterConfig):Unit = ()
 }
\ No newline at end of file