cmu.survey
Class Maintenance

java.lang.Object
  extended by cmu.survey.Maintenance

public class Maintenance
extends java.lang.Object

Used for debugging output, and automatic error message sending.
Send all your debugging output out with a static call to Maintenance.debugOutput(java.lang.String).
If you want that saved to a file, setDebuggingOutputFile(java.lang.String) (the default saves it to "DebuggingOutputForWebapp.txt")
If you want exceptions emailed to you, catch them in try/catch blocks, and then use sendBug(java.lang.String, java.lang.Throwable), and set the place you'd like them emailed to with setEmailToSendBugsTo(java.lang.String) and pick an SMTP server for mail to go through with setSmtpServer(java.lang.String)
If you're using multiple applications that are getting sent to a particular email and you don't know which application is sending the error, setLabelOfProgram(java.lang.String) so that it shows the name of the program in the debugging message (you can also send client info here if it's useful).
When an exception is emailed, it'll also send out the last several thousand lines of debugging output -- really useful for debugging stuff!


Field Summary
protected static boolean askUserWhetherToEmailEachErrorMessageIndividually
           
protected static boolean askUserWhetherToEmailErrorMessages
           
protected static java.io.File debuggingOutputFile
           
protected static java.lang.String debuggingOutputFileName
           
protected static boolean email_error_messages
           
protected static java.lang.String[] emailsToSendBugsTo
           
protected static java.lang.String emailToSendBugFrom
           
protected static java.io.PrintStream errorOutputStream
           
protected static java.lang.String firstBugNote
           
protected static boolean firstBugNoteSent
           
protected static boolean havePrintedEmailNotFoundWarningMessage
           
protected static java.lang.String labelOfProgram
           
protected static java.lang.String latestOutput
           
protected static int numberOfCharactersToSave
           
protected static boolean print_error_messages
           
protected static boolean save_error_messages_to_file
           
protected static boolean show_error_messages
           
protected static java.lang.String smtpServer
           
 
Constructor Summary
Maintenance()
           
 
Method Summary
static void addMaintenanceListener(MaintenanceListener listener)
           
static void catchUncaughtExceptions()
           
static void debugOutput(java.lang.Object output)
           
static void debugOutput(java.lang.String output)
           
static void debugOutput(java.lang.Throwable e)
           
static void debugOutputError(java.lang.String output)
           
static void debugOutputError(java.lang.String text, java.lang.Throwable e)
           
static void debugOutputError(java.lang.Throwable t)
           
static void debugOutputNoPrint(java.lang.String output)
           
static java.lang.String getDebuggingOutput()
           
static java.lang.String getDebuggingOutputFileName()
           
static java.lang.String[] getEmailsToSendBugsTo()
           
static java.lang.String getEmailToSendBugsFrom()
           
static java.lang.String getExceptionAsString(java.lang.Throwable exception)
           
static java.lang.String getInfoFrom(javax.servlet.jsp.PageContext pageContext)
           
static java.lang.String getLabelOfProgram()
           
static boolean getPrintErrorMessages()
           
static java.awt.Frame getShowErrorDialogsOnTopOfFrame()
           
static java.lang.String getSmtpServer()
           
static java.lang.String getStackTraceAsString(java.lang.Throwable exception)
           
static void main(java.lang.String[] args)
           
static java.lang.String printSaveErrorMessageString(java.lang.String errorMessage, java.lang.String userSaidInfo, java.lang.Throwable exception, java.lang.Object objectToGatherInformationAbout)
           
static java.lang.String printSaveErrorMessageString(java.lang.String errorMessage, java.lang.Throwable exception)
           
static boolean removeMaintenanceListener(MaintenanceListener listener)
           
static void saveDebugOutputToFile(java.lang.String output)
           
static java.lang.Exception sendBug(java.lang.String errorMessage)
           
static java.lang.Exception sendBug(java.lang.String errorMessage, java.lang.Object objectToGetInfoAbout)
           
static java.lang.Exception sendBug(java.lang.String subjectLine, java.lang.String errorMessage, java.lang.Object objectToGetInfoAbout)
           
static java.lang.Exception sendBug(java.lang.String errorMessage, java.lang.Throwable exception)
           
static java.lang.Exception sendBug(java.lang.String errorMessage, java.lang.Throwable exception, java.lang.Object objectToGatherInformationAbout)
           
static java.lang.Exception sendBug(java.lang.String errorMessage, java.lang.Throwable exception, java.lang.Object objectToGatherInformationAbout, java.lang.String subjectLine)
           
static java.lang.Exception sendBug(java.lang.Throwable exception)
           
static java.lang.String sendBugGetMessage(java.lang.Object errorMessage)
           
static java.lang.String sendBugGetMessage(java.lang.String errorMessage, java.lang.Throwable exception)
           
static java.lang.Exception sendErrorNotification(java.lang.String message)
           
static java.lang.Exception sendErrorNotification(java.lang.String message, javax.servlet.jsp.PageContext pageContext)
           
static java.lang.Exception sendErrorNotification(java.lang.String message, javax.servlet.jsp.PageContext pageContext, java.lang.Throwable t)
          Use this instead of sendBug when there's an error that the user has made configuring the application, or webapp, etc, that they should look into.
static java.lang.Exception sendErrorNotification(java.lang.String message, java.lang.Throwable t)
           
static java.lang.Exception sendHackerError(java.lang.String message, javax.servlet.jsp.PageContext pageContext)
           
static java.lang.Exception sendMail(java.lang.String from, java.lang.String[] to, java.lang.String subject, java.lang.String body)
           
static void setAskUserWhetherToEmailEachErrorMessageIndividually(boolean askUserEachTime)
           
static void setAskUserWhetherToEmailErrorMessages(boolean askUser)
           
static void setDebuggingOutputFile(java.io.File file)
           
static void setDebuggingOutputFile(java.io.PrintStream stream)
           
static void setDebuggingOutputFile(java.lang.String fileName)
           
static void setEmailsToSendBugsTo(java.lang.String[] emails)
           
static void setEmailToSendBugsFrom(java.lang.String email)
           
static void setEmailToSendBugsTo(java.lang.String email)
           
static void setEmailToSendBugsTo(java.lang.String[] emails)
           
static void setFirstBugNote(java.lang.String firstBugNote)
          If this is set, the first bug message sent out will include this message at the top explaining what a bug message is, and how to send it to the developer.
static void setLabelOfProgram(java.lang.String label)
           
static void setPrintErrorMessages(boolean printEm)
           
static void setSaveErrorMessagesToFiles(boolean saveEm)
           
static void setShowErrorDialogsOnTopOfFrame(java.awt.Frame showErrorDialogsOnTopOfFrame)
           
static void setSmtpServer(java.lang.String server)
           
static boolean shouldSendThisException(java.lang.Throwable t)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

emailsToSendBugsTo

protected static java.lang.String[] emailsToSendBugsTo

labelOfProgram

protected static java.lang.String labelOfProgram

show_error_messages

protected static boolean show_error_messages

email_error_messages

protected static boolean email_error_messages

print_error_messages

protected static boolean print_error_messages

save_error_messages_to_file

protected static boolean save_error_messages_to_file

errorOutputStream

protected static java.io.PrintStream errorOutputStream

numberOfCharactersToSave

protected static int numberOfCharactersToSave

latestOutput

protected static java.lang.String latestOutput

havePrintedEmailNotFoundWarningMessage

protected static boolean havePrintedEmailNotFoundWarningMessage

emailToSendBugFrom

protected static java.lang.String emailToSendBugFrom

smtpServer

protected static java.lang.String smtpServer

debuggingOutputFileName

protected static java.lang.String debuggingOutputFileName

debuggingOutputFile

protected static java.io.File debuggingOutputFile

askUserWhetherToEmailErrorMessages

protected static boolean askUserWhetherToEmailErrorMessages

askUserWhetherToEmailEachErrorMessageIndividually

protected static boolean askUserWhetherToEmailEachErrorMessageIndividually

firstBugNote

protected static java.lang.String firstBugNote

firstBugNoteSent

protected static boolean firstBugNoteSent
Constructor Detail

Maintenance

public Maintenance()
Method Detail

setLabelOfProgram

public static void setLabelOfProgram(java.lang.String label)

setFirstBugNote

public static void setFirstBugNote(java.lang.String firstBugNote)
If this is set, the first bug message sent out will include this message at the top explaining what a bug message is, and how to send it to the developer.

Parameters:
developerBugEmail -

getLabelOfProgram

public static java.lang.String getLabelOfProgram()

setEmailToSendBugsTo

public static void setEmailToSendBugsTo(java.lang.String email)

setEmailToSendBugsTo

public static void setEmailToSendBugsTo(java.lang.String[] emails)

setEmailsToSendBugsTo

public static void setEmailsToSendBugsTo(java.lang.String[] emails)

getEmailsToSendBugsTo

public static java.lang.String[] getEmailsToSendBugsTo()

setEmailToSendBugsFrom

public static void setEmailToSendBugsFrom(java.lang.String email)

setAskUserWhetherToEmailErrorMessages

public static void setAskUserWhetherToEmailErrorMessages(boolean askUser)

setAskUserWhetherToEmailEachErrorMessageIndividually

public static void setAskUserWhetherToEmailEachErrorMessageIndividually(boolean askUserEachTime)

setDebuggingOutputFile

public static void setDebuggingOutputFile(java.lang.String fileName)

setDebuggingOutputFile

public static void setDebuggingOutputFile(java.io.File file)

setDebuggingOutputFile

public static void setDebuggingOutputFile(java.io.PrintStream stream)

getDebuggingOutputFileName

public static java.lang.String getDebuggingOutputFileName()

setPrintErrorMessages

public static void setPrintErrorMessages(boolean printEm)

setSaveErrorMessagesToFiles

public static void setSaveErrorMessagesToFiles(boolean saveEm)

getPrintErrorMessages

public static boolean getPrintErrorMessages()

setSmtpServer

public static void setSmtpServer(java.lang.String server)

getSmtpServer

public static java.lang.String getSmtpServer()

setShowErrorDialogsOnTopOfFrame

public static void setShowErrorDialogsOnTopOfFrame(java.awt.Frame showErrorDialogsOnTopOfFrame)
Parameters:
showErrorDialogsOnTopOfFrame - The showErrorDialogsOnTopOfFrame to set.

getShowErrorDialogsOnTopOfFrame

public static java.awt.Frame getShowErrorDialogsOnTopOfFrame()
Returns:
Returns the showErrorDialogsOnTopOfFrame.

sendMail

public static java.lang.Exception sendMail(java.lang.String from,
                                           java.lang.String[] to,
                                           java.lang.String subject,
                                           java.lang.String body)

sendBug

public static java.lang.Exception sendBug(java.lang.String errorMessage,
                                          java.lang.Throwable exception)

getStackTraceAsString

public static java.lang.String getStackTraceAsString(java.lang.Throwable exception)

getExceptionAsString

public static java.lang.String getExceptionAsString(java.lang.Throwable exception)

printSaveErrorMessageString

public static java.lang.String printSaveErrorMessageString(java.lang.String errorMessage,
                                                           java.lang.Throwable exception)

printSaveErrorMessageString

public static java.lang.String printSaveErrorMessageString(java.lang.String errorMessage,
                                                           java.lang.String userSaidInfo,
                                                           java.lang.Throwable exception,
                                                           java.lang.Object objectToGatherInformationAbout)

sendBug

public static java.lang.Exception sendBug(java.lang.String errorMessage,
                                          java.lang.Throwable exception,
                                          java.lang.Object objectToGatherInformationAbout)

sendBug

public static java.lang.Exception sendBug(java.lang.String errorMessage,
                                          java.lang.Throwable exception,
                                          java.lang.Object objectToGatherInformationAbout,
                                          java.lang.String subjectLine)
Parameters:
errorMessage -
exception -
objectToGatherInformationAbout -
subjectLine -
Returns:

sendBug

public static java.lang.Exception sendBug(java.lang.String errorMessage)

sendBug

public static java.lang.Exception sendBug(java.lang.String errorMessage,
                                          java.lang.Object objectToGetInfoAbout)

sendBug

public static java.lang.Exception sendBug(java.lang.String subjectLine,
                                          java.lang.String errorMessage,
                                          java.lang.Object objectToGetInfoAbout)

sendBug

public static java.lang.Exception sendBug(java.lang.Throwable exception)

getInfoFrom

public static java.lang.String getInfoFrom(javax.servlet.jsp.PageContext pageContext)

sendHackerError

public static java.lang.Exception sendHackerError(java.lang.String message,
                                                  javax.servlet.jsp.PageContext pageContext)

sendErrorNotification

public static java.lang.Exception sendErrorNotification(java.lang.String message,
                                                        javax.servlet.jsp.PageContext pageContext,
                                                        java.lang.Throwable t)
Use this instead of sendBug when there's an error that the user has made configuring the application, or webapp, etc, that they should look into. The message should be good and easily readable by the user! For example, if the database can't be connected to, it's not a bug, it's an error and you may point them to directions on how to start the server and check it.

Parameters:
message -
pageContext -
Returns:

sendErrorNotification

public static java.lang.Exception sendErrorNotification(java.lang.String message,
                                                        javax.servlet.jsp.PageContext pageContext)

sendErrorNotification

public static java.lang.Exception sendErrorNotification(java.lang.String message,
                                                        java.lang.Throwable t)

sendErrorNotification

public static java.lang.Exception sendErrorNotification(java.lang.String message)

debugOutput

public static void debugOutput(java.lang.String output)

debugOutput

public static void debugOutput(java.lang.Object output)

debugOutputNoPrint

public static void debugOutputNoPrint(java.lang.String output)

debugOutputError

public static void debugOutputError(java.lang.String output)

debugOutputError

public static void debugOutputError(java.lang.Throwable t)
Parameters:
t -

debugOutput

public static void debugOutput(java.lang.Throwable e)

debugOutputError

public static void debugOutputError(java.lang.String text,
                                    java.lang.Throwable e)

saveDebugOutputToFile

public static void saveDebugOutputToFile(java.lang.String output)

sendBugGetMessage

public static java.lang.String sendBugGetMessage(java.lang.String errorMessage,
                                                 java.lang.Throwable exception)

sendBugGetMessage

public static java.lang.String sendBugGetMessage(java.lang.Object errorMessage)

getEmailToSendBugsFrom

public static java.lang.String getEmailToSendBugsFrom()

removeMaintenanceListener

public static boolean removeMaintenanceListener(MaintenanceListener listener)

addMaintenanceListener

public static void addMaintenanceListener(MaintenanceListener listener)

shouldSendThisException

public static boolean shouldSendThisException(java.lang.Throwable t)

getDebuggingOutput

public static java.lang.String getDebuggingOutput()
Returns:

catchUncaughtExceptions

public static void catchUncaughtExceptions()
Parameters:
string -

main

public static final void main(java.lang.String[] args)