com.sap.tc.logging
Class Log

java.lang.Object
  |
  +--com.sap.tc.logging.ExceptionHandling
        |
        +--com.sap.tc.logging.Log
All Implemented Interfaces:
java.lang.Cloneable, ILog, IObjectInfo
Direct Known Subclasses:
StreamLog

public abstract class Log
extends ExceptionHandling
implements ILog

Writes log records to destinations. Writing log records is done on behalf of log controllers. On logging calls, records are written to the destination associated with the log in the format dictated by the formatter registered with the log, if the severity and the filters set for the log do not veto.

Please find fundamental information about the principles of error handling in the package description. For this class, there are two cases where the methods ExceptionHandling.getException() and ExceptionHandling.throwException() are served. First, methods dealing with severities pass over a java.lang.IllegalArgumentException if a value is out of range. Second, output methods encountering problems leave the corresponding java.io.IOException. Some of these problems are also logged to the category /System/Logging which in turn writes messages to the console.

See Also:
LogController, Severity, Filter, Formatter, LogRecord

Field Summary
static int LOG_ACCESSABILITY_TYPE_LOCAL_LOG
          Inheritance is allowed, but with additional condition: final discretion of message printing lies with the original parent object.
static int LOG_ACCESSABILITY_TYPE_NORMAL_LOG
          This type of Log allows regular inheritance; this log will become available to all descendants of the parent object.
static int LOG_ACCESSABILITY_TYPE_PRIVATE_LOG
          This type of Log completely disables inheritance.
static int STATUS_CLOSED
           
static int STATUS_INVALID
           
static int STATUS_OPENED
           
 
Method Summary
 void addFilter(Filter filter)
          Adds another filter that controls writing of messages via this log.
 boolean beGroup()
          Deprecated. Not supported anymore. Always return False!
 boolean beLogged(int severity)
          Checks whether a message with the specified severity would be written via this log.
 void close()
          Closes output of this log object.
 void flush()
          Flushes buffered records in this log object.
 java.lang.String getDescription()
          Gets the description for this log.
 int getEffectiveSeverity()
          Gets the current effective severity of this log.
abstract  java.lang.String getEncoding()
          Gets the canonical name of the character encoding that is used for this log.
 java.util.Collection getFilters()
          Gets the filters that control writing of messages via this log.
 java.lang.String getFooter()
          Sets the footer text of this log.
 Formatter getFormatter()
          Gets the formatter that dictates the format of log records in this log.
 java.lang.String getHeader()
          Gets the header text of this log.
 int getLoggedCount()
           
 java.lang.String getLogName()
          Deprecated. @see {#getName()}.
 int getLogTypeAccessibility()
          Gets the current accessibility type of this log.
 java.lang.String getName()
          Gets the name for this log.
 int getNumberOfLogRecordsWritten()
          This method returns the number that indicates how many LogRecords have been written so far.
 java.util.List getOwners()
           
 LogRecord getRecord()
          Deprecated. - Not supported anymore - always return null
 java.lang.String getVerInUse()
          Gets the version of API.
 boolean isAutoFlush()
          Checks whether this log flushes its output stream after each log message.
 boolean isClosed()
          Check is this log closed.
 boolean isFiltersAgreeing(LogRecord rec)
          Checks whether all filters associated with this log controller agree with writing a log record.
 boolean isOpened()
          Check is this log opened.
 boolean isSuppressing()
           
 void open()
          open output of this log object.
 void removeFilter(Filter filter)
          Removes a filter so that it no longer controls writing of messages via this log.
 void removeFilters()
          Removes all filters associated with this log.
 void reset()
          Reset all current Log settings and starts from beginning Current file
 void resetLoggedCount()
           
 void setAutoFlush(boolean autoFlush)
          Configures this log to flush the output stream after each log message.
 void setDescription(java.lang.String value)
          Sets a description for this log.
 void setEffectiveSeverity(int severity)
          Sets the effective severity of this log.
abstract  void setEncoding(java.lang.String enc)
          Sets the named character encoding to be used for this log.
 void setFormatter(Formatter formatter)
          Sets the formatter that dictates the format of log records in this log.
 void setLogName(java.lang.String name)
          Deprecated. @see {#setName(String name)}.
 void setLogTypeAccessibility(int value)
          Sets the accessibility level for this log.
 void setName(java.lang.String name)
          Sets a name for this log.
 void setSuppressing(boolean suppressing)
           
 long size()
          Current size of the log.
 int status()
          Status of this log object.
 LogRecord write(LogRecord rec)
          Deprecated. not supported anymore
 
Methods inherited from class com.sap.tc.logging.ExceptionHandling
getException, getExceptions, handleException, handleException, resetException, throwException
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATUS_INVALID

public static final int STATUS_INVALID

STATUS_CLOSED

public static final int STATUS_CLOSED

STATUS_OPENED

public static final int STATUS_OPENED

LOG_ACCESSABILITY_TYPE_NORMAL_LOG

public static final int LOG_ACCESSABILITY_TYPE_NORMAL_LOG
This type of Log allows regular inheritance; this log will become available to all descendants of the parent object. The corresponding API is: static final Location parent = Location.getLocation(“com.sap�), Location child = Location.getLocation(“com.sap.foo�); parent.addLog(new ConsoleLog()); parent.setEffectiveSeverity(Severity.NONE); child.setEffectiveSeverity(Severity.INFO); child.fatalT(“A fatal message from children�); This is an unconditional inheritance. As long as the message passes the evaluation of severity and filter of the child object, it will be printed out via the inherited log, in this case, ConsoleLog.

LOG_ACCESSABILITY_TYPE_LOCAL_LOG

public static final int LOG_ACCESSABILITY_TYPE_LOCAL_LOG
Inheritance is allowed, but with additional condition: final discretion of message printing lies with the original parent object. The log is local, in the sense that it is not available for the descendants if the child message does not pass the severity and filter test of the parent object. static final Location parent = Location.getLocation(“com.sap�) Location child = Location.getLocation(“com.sap.foo�); parent.addLocalLog(new ConsoleLog()); parent.setEffectiveSeverity(Severity.NONE); child.setEffectiveSeverity(Severity.INFO); child.fatalT(“A fatal message from children�); Contrary to the NORMAL Log example, the child message will not be printed because it does not pass the severity test of the parent.

LOG_ACCESSABILITY_TYPE_PRIVATE_LOG

public static final int LOG_ACCESSABILITY_TYPE_PRIVATE_LOG
This type of Log completely disables inheritance. Log assignment is private: only effective for the parent source object. static final Location parent = Location.getLocation(“com.sap�), Location child = Location.getLocation(“com.sap.foo�); parent.addPrivateLog(new ConsoleLog()); child.setEffectiveSeverity(Severity.INFO); child.fatalT(“A fatal message from children�); In this case, child object does not inherit any destination log at all. Nothing will be printed even the message passes all the severity and filter tests.
Method Detail

getName

public java.lang.String getName()
Gets the name for this log. Can be null.
Specified by:
getName in interface IObjectInfo

setName

public void setName(java.lang.String name)
Sets a name for this log. An optional courtesy feature for user to easily refer to a log. Highly recommended if logviewer tool will be used to browse the output messages. If no name is specified, nothing will be set and the value is null.

getDescription

public java.lang.String getDescription()
Gets the description for this log. Can be null.
Specified by:
getDescription in interface IObjectInfo

setDescription

public void setDescription(java.lang.String value)
Sets a description for this log. An optional courtesy feature for user to easily refer to a log. Highly recommended if logviewer tool will be used to browse the output messages. If no name is specified, nothing will be set and the value is null.

getVerInUse

public java.lang.String getVerInUse()
Gets the version of API.
Specified by:
getVerInUse in interface IObjectInfo

status

public int status()
Status of this log object. STATUS_CLOSE == 1 STATUS_OPEN == 2
Specified by:
status in interface ILog

getHeader

public java.lang.String getHeader()
Gets the header text of this log.
Specified by:
getHeader in interface ILog
Returns:
Text which represent header of this log.
See Also:
#setHeader(java.lang.String)

getFooter

public java.lang.String getFooter()
Sets the footer text of this log.
Specified by:
getFooter in interface ILog
Returns:
Text which represent footer of this log.
See Also:
#setHeader(java.lang.String)

getEffectiveSeverity

public int getEffectiveSeverity()
Gets the current effective severity of this log.
Specified by:
getEffectiveSeverity in interface ILog
Returns:
Effective severity

setEffectiveSeverity

public void setEffectiveSeverity(int severity)
Sets the effective severity of this log.
Specified by:
setEffectiveSeverity in interface ILog
Parameters:
severity - New effective severity

getLogTypeAccessibility

public int getLogTypeAccessibility()
Gets the current accessibility type of this log. Default = LOG_ACCESSABILITY_TYPE_NORMAL_LOG
Specified by:
getLogTypeAccessibility in interface ILog
Returns:
Accessibility type. LOG_ACCESSABILITY_TYPE_NORMAL_LOG LOG_ACCESSABILITY_TYPE_LOCAL_LOG LOG_ACCESSABILITY_TYPE_PRIVATE_LOG.

setLogTypeAccessibility

public void setLogTypeAccessibility(int value)
Sets the accessibility level for this log. Note: If you specified value which is not recognized, the accessibility type will be set to PRIVATE.
Specified by:
setLogTypeAccessibility in interface ILog
Parameters:
new - accessibility type LOG_ACCESSABILITY_TYPE_NORMAL_LOG LOG_ACCESSABILITY_TYPE_LOCAL_LOG LOG_ACCESSABILITY_TYPE_PRIVATE_LOG.

getFormatter

public Formatter getFormatter()
Gets the formatter that dictates the format of log records in this log.
Specified by:
getFormatter in interface ILog
Returns:
Formatter
See Also:
setFormatter(Formatter)

setFormatter

public void setFormatter(Formatter formatter)
Sets the formatter that dictates the format of log records in this log. Note: If you send a null like argument the default formater (ListFormatter), will be created.
Specified by:
setFormatter in interface ILog
Returns:
Formatter
See Also:
getFormatter()

getNumberOfLogRecordsWritten

public int getNumberOfLogRecordsWritten()
This method returns the number that indicates how many LogRecords have been written so far. This does not take into account how many LogRecords were there in the file before the current session has started. Therefore, please note that this number deals with the number of LogRecords that have been written in the current session.
Specified by:
getNumberOfLogRecordsWritten in interface ILog
Returns:
int Number of LogRecords written so far in the current session.

size

public long size()
Current size of the log.
Returns:
long size of the log.

getEncoding

public abstract java.lang.String getEncoding()
Gets the canonical name of the character encoding that is used for this log. If no character encoding is set the default character encoding of the platform is used.
Specified by:
getEncoding in interface ILog
Returns:
Name of character encoding
See Also:
setEncoding(java.lang.String)

setEncoding

public abstract void setEncoding(java.lang.String enc)
Sets the named character encoding to be used for this log. If no character encoding is set the default character encoding is used.
Specified by:
setEncoding in interface ILog
Parameters:
enc - Name of character encoding
See Also:
getEncoding()

isFiltersAgreeing

public boolean isFiltersAgreeing(LogRecord rec)
Checks whether all filters associated with this log controller agree with writing a log record.
Parameters:
rec - Log record to be written
Returns:
No filter vetoes writing

getFilters

public java.util.Collection getFilters()
Gets the filters that control writing of messages via this log.
Specified by:
getFilters in interface ILog
Returns:
Unmodifiable collection of filters associated with this log

addFilter

public void addFilter(Filter filter)
Adds another filter that controls writing of messages via this log. The results of all filters for a given message are logically anded to determine whether a message is to be written.
Specified by:
addFilter in interface ILog
Parameters:
filter - New filter

removeFilter

public void removeFilter(Filter filter)
Removes a filter so that it no longer controls writing of messages via this log.
Specified by:
removeFilter in interface ILog
Parameters:
filter - Filter to be removed

removeFilters

public void removeFilters()
Removes all filters associated with this log.
Specified by:
removeFilters in interface ILog

beLogged

public boolean beLogged(int severity)
Checks whether a message with the specified severity would be written via this log. The purpose of this method is to avoid evaluating the arguments of a logging call, which is expensive and would be superfluous if a message is not written because of its insufficient severity. The result returned is necessary but not sufficient for writing log messages, that is if the method returns false the message is not going to be written but not vice versa. To this end, the method checks whether the specified severity is equal to or higher than the effective severity of the log. It does not take into account filters associated with the log.
Specified by:
beLogged in interface ILog
Parameters:
severity - Severity of message to be written

write

public LogRecord write(LogRecord rec)
Deprecated. not supported anymore

Writes a log record to this log if no filter vetoes.
Parameters:
rec - Record to be written

flush

public void flush()
Flushes buffered records in this log object.
Specified by:
flush in interface ILog

isAutoFlush

public boolean isAutoFlush()
Checks whether this log flushes its output stream after each log message. Automatic flushing is switched on in a new log.
Specified by:
isAutoFlush in interface ILog
Returns:
true if and only if this log flushes its output stream after each log message
See Also:
setAutoFlush(boolean)

setAutoFlush

public void setAutoFlush(boolean autoFlush)
Configures this log to flush the output stream after each log message. Automatic flushing is switched on in a new log.
Specified by:
setAutoFlush in interface ILog
Parameters:
autoFlush -  
See Also:
isAutoFlush()

open

public void open()
open output of this log object.
Specified by:
open in interface ILog

close

public void close()
Closes output of this log object.
Specified by:
close in interface ILog

isClosed

public boolean isClosed()
Check is this log closed. Helper method. Same like: status() == STATUS_CLOSED
Specified by:
isClosed in interface ILog

isOpened

public boolean isOpened()
Check is this log opened. Helper method. Same like: status() == STATUS_OPENED
Specified by:
isOpened in interface ILog

reset

public void reset()
Reset all current Log settings and starts from beginning Current file

isSuppressing

public boolean isSuppressing()

setSuppressing

public void setSuppressing(boolean suppressing)

getLoggedCount

public int getLoggedCount()

resetLoggedCount

public void resetLoggedCount()

getOwners

public java.util.List getOwners()

getRecord

public LogRecord getRecord()
Deprecated. - Not supported anymore - always return null


beGroup

public boolean beGroup()
Deprecated. Not supported anymore. Always return False!

See Also:
#LogController.beGroup()

getLogName

public java.lang.String getLogName()
Deprecated. @see {#getName()}.


setLogName

public void setLogName(java.lang.String name)
Deprecated. @see {#setName(String name)}.