MDi JLib
1.7.4

com.microdeveloper.servlets.io
Class LogServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by com.microdeveloper.servlets.io.LogServlet
All Implemented Interfaces:
Serializable, Servlet, ServletConfig

public abstract class LogServlet
extends HttpServlet

A logging class used for tracking events generated by a Servlet.

Logging messages can be embedded in the servlet and activated on demand. The default state is off, but by enabling the logging servlet, these messages can be sent back for debugging purposes.

Override this class and call logMessage() to add messages to the log.

Override doGet() to disable the error logging feature for production.

Example:

 

public class EchoServlet extends LogServlet {

public void doPost( PrintWriter out , Hashtable parms ) { String text = parms.getString( "text" ); if ( usable( text ) ) { for ( int i = 0 ; i < 100 ; i++ ) { out.println( text + "<br>" ); } } else { reportProblem( out , "invalid parameters" ); } }

}

Copyright (c) 2004-2007 MicroDeveloper, Inc.

Since:
1.5.0
Version:
1.1
See Also:
Serialized Form

Field Summary
protected  int getCount
          increment this if you override the traditional doGet()
protected  int postCount
          increment this if you override the traditional doPost()
 
Constructor Summary
protected LogServlet()
           
 
Method Summary
protected  void checkConsoleLogging()
          Call this as the first thing you do if you override the traditional doGet() or doPost().
 void debugReport(PrintWriter out)
          Override this if you have more to say in the GET debug information.
 void doGet(HttpServletRequest req, HttpServletResponse resp)
          Override this to make the debugger log unavailable.
protected  void doGet(PrintWriter out, Hashtable parameters)
          if you need doGet, override this instead of the normal doGet.
 void doPost(HttpServletRequest req, HttpServletResponse resp)
           
protected  void doPost(PrintWriter out, Hashtable parameters)
          if you need doPost(), override this instead of the normal doPost().
 void emailMessage(PrintWriter out, String s)
          E-mail a message to the admin, send it to the user and add it to the log.
 void emailMessage(String s)
          E-mail a message to the admin and add the same message to the log.
 void init(ServletConfig config)
           
 void logMessage(String s)
          Add a message to the log.
protected  void reportProblem(PrintWriter out, String message)
          This convenience method sends the message to the log and sends it to out.
static void setAccessParameterName(String value)
           
static void setAccessParameterValue(String value)
           
protected  void setLogConsole(boolean on)
          Messages are sent to STDOUT so they can be tracked in the servlet server logs.
protected  void setLogMemory(boolean on)
          Messages are logged to memory so they can be viewed by a GET command.
protected  boolean usable(String s)
          Convenience method - returns true if the string is not null and not empty.
 
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, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

postCount

protected int postCount
increment this if you override the traditional doPost()


getCount

protected int getCount
increment this if you override the traditional doGet()

Constructor Detail

LogServlet

protected LogServlet()
Method Detail

init

public void init(ServletConfig config)
          throws ServletException
Specified by:
init in interface Servlet
Overrides:
init in class GenericServlet
Throws:
ServletException

setAccessParameterName

public static void setAccessParameterName(String value)

setAccessParameterValue

public static void setAccessParameterValue(String value)

setLogMemory

protected void setLogMemory(boolean on)
Messages are logged to memory so they can be viewed by a GET command.


setLogConsole

protected void setLogConsole(boolean on)
Messages are sent to STDOUT so they can be tracked in the servlet server logs.


checkConsoleLogging

protected void checkConsoleLogging()
Call this as the first thing you do if you override the traditional doGet() or doPost().

This makes sure that console logging is turned off if it is no longer desired.


logMessage

public void logMessage(String s)
Add a message to the log.


reportProblem

protected void reportProblem(PrintWriter out,
                             String message)
This convenience method sends the message to the log and sends it to out.


usable

protected boolean usable(String s)
Convenience method - returns true if the string is not null and not empty.


emailMessage

public void emailMessage(String s)
E-mail a message to the admin and add the same message to the log.


emailMessage

public void emailMessage(PrintWriter out,
                         String s)
E-mail a message to the admin, send it to the user and add it to the log.


debugReport

public void debugReport(PrintWriter out)
Override this if you have more to say in the GET debug information.


doPost

protected void doPost(PrintWriter out,
                      Hashtable parameters)
if you need doPost(), override this instead of the normal doPost().

Parameters:
out - use this to send HTML to the browser.

parameters - all of the parameters sent to the servlet are stored in this hash table.


doPost

public void doPost(HttpServletRequest req,
                   HttpServletResponse resp)
            throws ServletException,
                   IOException
Overrides:
doPost in class HttpServlet
Throws:
ServletException
IOException

doGet

protected void doGet(PrintWriter out,
                     Hashtable parameters)
if you need doGet, override this instead of the normal doGet.

Parameters:
out - use this to send HTML to the browser.

parameters - all of the parameters sent to the servlet are stored in this hash table.


doGet

public void doGet(HttpServletRequest req,
                  HttpServletResponse resp)
Override this to make the debugger log unavailable.

Overrides:
doGet in class HttpServlet

MDi JLib
1.7.4

Copyright©2001-2007 MicroDeveloper, Inc. All Rights Reserved.