|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--HttpServlet | +--com.javaranch.common.LogServlet
Used for tracking events in a Servlet.
Log messages are sent to a logging object that defaults to being turned off. Activating the servlet via a web browser gives you access to activate logging 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 , CastMap 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) 1999-2004 Paul Wheaton
Copyright (c) 1999-2000 EarthWatch, Inc.
You are welcome to do whatever you want to with this source file provided that you maintain this comment fragment (between the dashed lines). Modify it, change the package name, change the class name ... personal or business use ... sell it, share it ... add a copyright for the portions you add ...
My goal in giving this away and maintaining the copyright is to hopefully direct developers back to JavaRanch.
I originally developed this class while working as a contractor at EarthWatch, Inc. in Longmont, Colorado. They gave me permission to distribute this code this way provided that their message would also be carried along. Their message is that they hire Java programmers and would like you to consider working with them. I have to say that my experience with them was first rate and I would encourage engineers to work there. Check out their web site at http://www.digitalglobe.com.
The original source can be found at JavaRanch
- - - - - - - - - - - - - - - - -
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 | |
LogServlet()
|
Method Summary | |
protected void |
checkConsoleLogging()
Call this as the first thing you do if you override the traditional doGet() or doPost(). |
void |
debugReport(java.io.PrintWriter out)
Override this if you have more to say in the GET debug information. |
protected void |
doGet(java.io.PrintWriter out,
CastMap parameters)
if you need doGet, override this instead of the normal doGet. |
protected void |
doPost(java.io.PrintWriter out,
CastMap parameters)
if you need doPost(), override this instead of the normal doPost(). |
void |
emailMessage(java.io.PrintWriter out,
java.lang.String s)
E-mail a message to the admin, send it to the user and add it to the log. |
void |
emailMessage(java.lang.String s)
E-mail a message to the admin and add the same message to the log. |
void |
logMessage(java.lang.String s)
Add a message to the log. |
protected void |
reportProblem(java.io.PrintWriter out,
java.lang.String message)
This convenience method sends the message to the log and sends it to out. |
static void |
setAccessParameterName(java.lang.String accessParameterName)
|
static void |
setAccessParameterValue(java.lang.String accessParameterValue)
|
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(java.lang.String s)
Deprecated. use Str.usable() instead |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected int postCount
protected int getCount
Constructor Detail |
public LogServlet()
Method Detail |
public static void setAccessParameterName(java.lang.String accessParameterName)
public static void setAccessParameterValue(java.lang.String accessParameterValue)
protected void setLogMemory(boolean on)
protected void setLogConsole(boolean on)
protected void checkConsoleLogging()
This makes sure that console logging is turned off if it is no longer desired.
public void logMessage(java.lang.String s)
protected void reportProblem(java.io.PrintWriter out, java.lang.String message)
protected boolean usable(java.lang.String s)
public void emailMessage(java.lang.String s)
public void emailMessage(java.io.PrintWriter out, java.lang.String s)
public void debugReport(java.io.PrintWriter out)
protected void doPost(java.io.PrintWriter out, CastMap 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. protected void doGet(java.io.PrintWriter out, CastMap 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.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |