com.sas.util
Class SystemLog

com.sas.util.SystemLog
All Implemented Interfaces:
ErrorHandlerInterface

public class SystemLog
implements ErrorHandlerInterface

SystemLog provides a consistent way for applications and applets to report and/or record errors, warnings, and notable conditions that occur.

By default, the errorLog, warningLog, and noteLog use the same SystemLog. You can change this by setting the appropriate field on the SysteLog class.


Field Summary
static SystemLog errorLog
           
protected  boolean logStackTraces
           
static SystemLog noteLog
           
protected  java.io.PrintWriter stream
           
protected  java.text.DateFormat timestamp
           
protected  boolean timestampUsed
           
static SystemLog warningLog
           
 
Constructor Summary
SystemLog()
          Default constructor.
SystemLog(java.io.PrintWriter stream)
          Constructor that takes a stream to write to.
 
Method Summary
 void clear()
          Clears the log.
 boolean getLogStackTraces()
          Returns whether stack traces are appended to log when printToLog() is called.
 java.io.PrintWriter getPrintWriter()
          Returns the stream to append messages to.
 java.text.DateFormat getTimestamp()
          Returns the time stamp format used when appending the time to the log.
 void handleError(com.sas.ComponentInterface component, com.sas.text.Message message, java.lang.String messageCode)
          Print the specified error to the error log.
 boolean isTimestampUsed()
          Returns whether times stamps are appended to log when printToLog() is called.
static void logError(java.lang.String msg)
           
static void logException(java.lang.String msg, java.lang.Throwable throwable)
           
static void logNote(java.lang.String msg)
           
static void logWarning(java.lang.String msg)
           
 void printStackTrace()
          Prints a stack trace to the log.
 void printToLog(java.lang.String type, java.lang.String msg)
          Print the specified message to the log.
 void setLogStackTraces(boolean logStackTraces)
          Sets whether stack traces are appended to log when printToLog() is called.
 void setPrintWriter(java.io.PrintWriter stream)
          Sets the stream to append messages to.
 void setTimestamp(java.text.DateFormat timestamp)
          Sets the time stamp format used when appending the time to the log.
 void setTimestampUsed(boolean timestampUsed)
          Sets whether time stamps are appended to log when printToLog() is called.
 

Field Detail

noteLog

public static SystemLog noteLog

errorLog

public static SystemLog errorLog

warningLog

public static SystemLog warningLog

stream

protected java.io.PrintWriter stream

logStackTraces

protected boolean logStackTraces

timestampUsed

protected boolean timestampUsed

timestamp

protected java.text.DateFormat timestamp
Constructor Detail

SystemLog

public SystemLog()
Default constructor. Defaults to using System.err for output.


SystemLog

public SystemLog(java.io.PrintWriter stream)
Constructor that takes a stream to write to.

Method Detail

logNote

public static void logNote(java.lang.String msg)

logError

public static void logError(java.lang.String msg)

logWarning

public static void logWarning(java.lang.String msg)

logException

public static void logException(java.lang.String msg,
                                java.lang.Throwable throwable)

getPrintWriter

public java.io.PrintWriter getPrintWriter()
Returns the stream to append messages to.

Returns:
the stream to append messages to.

setPrintWriter

public void setPrintWriter(java.io.PrintWriter stream)
Sets the stream to append messages to.

Parameters:
stream - the stream to append messages to.

getLogStackTraces

public boolean getLogStackTraces()
Returns whether stack traces are appended to log when printToLog() is called.

Returns:
whether stack traces are appended to log when printToLog() is called.

setLogStackTraces

public void setLogStackTraces(boolean logStackTraces)
Sets whether stack traces are appended to log when printToLog() is called.

Parameters:
logStackTraces - whether stack traces are appended to log when printToLog() is called.

isTimestampUsed

public boolean isTimestampUsed()
Returns whether times stamps are appended to log when printToLog() is called.

Returns:
whether times stamps are appended to log when printToLog() is called.

setTimestampUsed

public void setTimestampUsed(boolean timestampUsed)
Sets whether time stamps are appended to log when printToLog() is called.

Parameters:
timestampUsed - whether time stamps are appended to log when printToLog() is called.

getTimestamp

public java.text.DateFormat getTimestamp()
Returns the time stamp format used when appending the time to the log.

Returns:
the time stamp format used when appending the time to the log.

setTimestamp

public void setTimestamp(java.text.DateFormat timestamp)
Sets the time stamp format used when appending the time to the log.

Parameters:
timestamp - the time stamp format used when appending the time to the log.

printStackTrace

public void printStackTrace()
Prints a stack trace to the log.


handleError

public void handleError(com.sas.ComponentInterface component,
                        com.sas.text.Message message,
                        java.lang.String messageCode)
Print the specified error to the error log.

Specified by:
handleError in interface ErrorHandlerInterface
Parameters:
component - The component on which the error occured.
message - A Message object with formatted with the message to display. The object should also contain the necessary arguments for formatting the message.
messageCode - A non-translatable string which indicates the type of error that occured.
See Also:
ErrorHandlerInterface

printToLog

public void printToLog(java.lang.String type,
                       java.lang.String msg)
Print the specified message to the log.

Parameters:
type - The type of message : Error, Warning, or Note
msg - The message to print to the log.

clear

public void clear()
Clears the log. May not work for all logs.




Copyright © 2009 SAS Institute Inc. All Rights Reserved.