com.twitter.common.net.http.handlers
Class LogPrinter

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by com.twitter.common.net.http.handlers.StringTemplateServlet
              extended by com.twitter.common.net.http.handlers.LogPrinter
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class LogPrinter
extends StringTemplateServlet

HTTP handler to page through log files. Supports GET and POST requests. GET requests are responsible for fetching chrome and javascript, while the POST requests are used to fetch actual log data. TODO(William Farner): Change all links (Next, Prev, filter) to issue AJAX requests rather than reloading the page.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.twitter.common.net.http.handlers.StringTemplateServlet
StringTemplateServlet.CacheTemplates
 
Field Summary
static String LOG_DIR_KEY
          A @Named binding key for the log directory to display by default.
 
Constructor Summary
LogPrinter(File logDir, boolean cacheTemplates)
           
 
Method Summary
protected  void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Fetches the chrome for the page.
protected  void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          A POST request is made from javascript, to request the contents of a log file.
protected static String filterLines(String text, String filterRegexp)
           
 
Methods inherited from class com.twitter.common.net.http.handlers.StringTemplateServlet
writeTemplate, writeTemplate
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG_DIR_KEY

public static final String LOG_DIR_KEY
A @Named binding key for the log directory to display by default.

See Also:
Constant Field Values
Constructor Detail

LogPrinter

@Inject
public LogPrinter(File logDir,
                         boolean cacheTemplates)
Method Detail

doPost

protected void doPost(javax.servlet.http.HttpServletRequest req,
                      javax.servlet.http.HttpServletResponse resp)
               throws javax.servlet.ServletException,
                      IOException
A POST request is made from javascript, to request the contents of a log file. In order to fulfill the request, the 'file' parameter must be set in the request.

Overrides:
doPost in class javax.servlet.http.HttpServlet
Parameters:
req - Servlet request.
resp - Servlet response.
Throws:
javax.servlet.ServletException - If there is a problem with the servlet.
IOException - If there is a problem reading/writing data to the client.

doGet

protected void doGet(javax.servlet.http.HttpServletRequest req,
                     javax.servlet.http.HttpServletResponse resp)
              throws javax.servlet.ServletException,
                     IOException
Fetches the chrome for the page. If a file is requested, a page will be returned that uses an AJAX request to fetch the log contents. If no file is specified, then a file listing is displayed.

Overrides:
doGet in class javax.servlet.http.HttpServlet
Parameters:
req - Servlet request.
resp - Servlet response.
Throws:
javax.servlet.ServletException - If there is a problem with the servlet.
IOException - If there is a problem reading/writing data to the client.

filterLines

protected static String filterLines(String text,
                                    String filterRegexp)