com.sap.ip.me.api.logging
Class AbstractLogging

java.lang.Object
  extended bycom.sap.ip.me.api.logging.AbstractLogging
Direct Known Subclasses:
AppLog, Trace

public abstract class AbstractLogging
extends java.lang.Object

This abstract class contains a set of pre implemented methods for logging. It is the parent for the Mobile Infrastructure Trace and AppLog .

Version:
2.5
Author:
SAP

Field Summary
protected static java.lang.String CONFIGURATION_PREFIX
          The prefix for all Mobile Infrastructure log configurations.
protected static java.lang.String LOG_ENABLED_SUFFIX
          The enabled suffix of a Mobile Infrastructure log configuration.
protected static java.lang.String LOG_LEVEL_SUFFIX
          The log level suffix of a Mobile Infrastructure log configuration.
protected static java.lang.String LOGWRITER_IMPLEMENTATION_SUFFIX
          The suffix for the configuration of the implementation class of the log writer.
 
Constructor Summary
AbstractLogging()
           
 
Method Summary
 java.lang.String getComponent()
          Gets the component name for this log instance.
abstract  int getEffectiveSeverity()
          Gets the current log level of the log
 java.io.InputStream getLogContentAsStream()
          Returns an input stream with the log content.
protected  java.lang.String getLogLevelName(int logLevel)
          Gets the logLevelName attribute of the AbstractLogging object
protected abstract  LogWriter getLogWriter()
          Returns the LogWriter instance of this log.
protected abstract  java.lang.String getLogWriterClassname()
          Gets the configured filename / path of the log.
 java.io.Writer getWriter(int severity, java.lang.String message)
          Writes a given message to trace (with prefix "Start: ") and returns current log writer.
abstract  boolean isLogging(int severity)
          Returns true iff the given log severity will be logged.
abstract  boolean isOn()
          Gets the current activation state of the log.
 void log(int severity, java.lang.String message)
          Logs the message if log is switched on and the given severity will be logged.
 void log(int severity, java.lang.String message, java.lang.Object param)
          Logs the message if log is switched on and the given severity will be logged.
 void log(int severity, java.lang.String message, java.lang.Object[] params)
          Logs the message if log is switched on and the given severity will be logged.
 void log(int severity, java.lang.String message, java.lang.Object param1, java.lang.Object param2)
          Logs the message if log is switched on and the given severity will be logged.
 void log(int severity, java.lang.String message, java.lang.Object param1, java.lang.Object param2, java.lang.Object param3)
          Logs the message if log is switched on and the given severity will be logged.
 void log(java.lang.String message)
          Logs the message if log is switched on and severity INFO_LEVEL will be logged.
 void log(java.lang.String message, java.lang.Object param1)
          Logs the message if log is switched on and severity INFO_LEVEL will be logged.
 void log(java.lang.String message, java.lang.Object[] params)
          Logs the message if log is switched on and severity INFO_LEVEL will be logged.
 void log(java.lang.String message, java.lang.Object param1, java.lang.Object param2)
          Logs the message if log is switched on and severity INFO_LEVEL will be logged.
 void log(java.lang.String message, java.lang.Object param1, java.lang.Object param2, java.lang.Object param3)
          Logs the message if log is switched on and severity INFO_LEVEL will be logged.
 void logException(int severity, java.lang.String message, java.lang.Object[] params, java.lang.Throwable t, boolean printStackTrace)
          Logs an Exception with the given message if log is switched on.
 void logException(int severity, java.lang.String message, java.lang.Throwable t, boolean printStackTrace)
          Logs an Exception with the given message if log is switched on.
 void logException(int severity, java.lang.Throwable t)
          Logs an Exception without any additional message if log is switched on.
 void logException(int severity, java.lang.Throwable t, boolean printStackTrace)
          Logs an Exception without any additional message if log is switched on.
 void logException(java.lang.String message, java.lang.Throwable t, boolean printStackTrace)
          Logs an Exception with the given message if log is switched on.
 void logException(java.lang.Throwable t)
          Logs an Exception without any additional message if log is switched on.
 void logException(java.lang.Throwable t, boolean printStackTrace)
          Logs an Exception without any additional message if log is switched on.
 void logFileContent(int severity, java.io.File file)
          Logs the content of a file into the log file if log is switched on and the trace level is less or equal the current trace level.
 void logFileContent(int severity, java.io.File file, java.lang.String encoding)
          Logs the content of a file into the log file if log is switched on and the trace level is less or equal the current trace level.
 java.util.Vector read()
          Reads the trace file and returns an String - Enumeration of the log file lines.
protected abstract  void readConfiguration(java.lang.String logName)
          Reads the configuration for the given log.
abstract  void refresh()
          Do not use this method.
 void releaseWriter(int severity, java.lang.String message)
          Writes a given message to trace (with prefix "End: ") and updates internal status.
 void reset()
          Resets the log.
protected  void setComponent(java.lang.String componentname)
          Sets the component name for this instance.
abstract  void setEffectiveSeverity(int severity)
          Gets the current log level of the log
protected abstract  void setLogWriter(LogWriter newLogWriter)
          Sets the LogWriter instance.
protected abstract  void setOn(boolean on)
          Sets the current activation state of the log.
abstract  boolean switchOn(boolean on)
          Turns the log on or off.
protected  void writeConfiguration(java.lang.String logName, boolean userdependant)
          Writes the configuration for the given log.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONFIGURATION_PREFIX

protected static final java.lang.String CONFIGURATION_PREFIX
The prefix for all Mobile Infrastructure log configurations.

See Also:
Constant Field Values

LOG_ENABLED_SUFFIX

protected static final java.lang.String LOG_ENABLED_SUFFIX
The enabled suffix of a Mobile Infrastructure log configuration.

See Also:
Constant Field Values

LOG_LEVEL_SUFFIX

protected static final java.lang.String LOG_LEVEL_SUFFIX
The log level suffix of a Mobile Infrastructure log configuration.

See Also:
Constant Field Values

LOGWRITER_IMPLEMENTATION_SUFFIX

protected static final java.lang.String LOGWRITER_IMPLEMENTATION_SUFFIX
The suffix for the configuration of the implementation class of the log writer.

See Also:
Constant Field Values
Constructor Detail

AbstractLogging

public AbstractLogging()
Method Detail

logFileContent

public final void logFileContent(int severity,
                                 java.io.File file)
Logs the content of a file into the log file if log is switched on and the trace level is less or equal the current trace level. The file will be read with "UTF8" encoding

Parameters:
severity - The severity for this message.
file - The file that has to be logged.

log

public void log(int severity,
                java.lang.String message)
Logs the message if log is switched on and the given severity will be logged.

Parameters:
severity - The severity for this message.
message - The message that has to be logged.

log

public void log(int severity,
                java.lang.String message,
                java.lang.Object param)
Logs the message if log is switched on and the given severity will be logged.

Parameters:
severity - The severity for this message.
message - The message that has to be logged. See java.text.MessageFormat for the format of this string.
param - The parameter for the message. See java.text.MessageFormat .
See Also:
for further details.

log

public void log(int severity,
                java.lang.String message,
                java.lang.Object param1,
                java.lang.Object param2)
Logs the message if log is switched on and the given severity will be logged.

Parameters:
severity - The severity for this message.
message - The message that has to be logged. See java.text.MessageFormat for the format of this string.
param1 - The first parameter for the message. See java.text.MessageFormat .
param2 - The second parameter for the message. See java.text.MessageFormat .
See Also:
for further details.

log

public void log(int severity,
                java.lang.String message,
                java.lang.Object param1,
                java.lang.Object param2,
                java.lang.Object param3)
Logs the message if log is switched on and the given severity will be logged.

Parameters:
severity - The severity for this message.
message - The message that has to be logged. See java.text.MessageFormat for the format of this string.
param1 - The first parameter for the message. See java.text.MessageFormat .
param2 - The second parameter for the message. See java.text.MessageFormat .
param3 - The third parameter for the message. See java.text.MessageFormat .
See Also:
for further details.

log

public void log(int severity,
                java.lang.String message,
                java.lang.Object[] params)
Logs the message if log is switched on and the given severity will be logged.

Parameters:
severity - The severity for this message.
message - The message that has to be logged. See java.text.MessageFormat for the format of this string.
params - The parameter list for the message. See java.text.MessageFormat .
See Also:
for further details.

log

public void log(java.lang.String message)
Logs the message if log is switched on and severity INFO_LEVEL will be logged. The severity for this message is INFO_LEVEL.

Parameters:
message - The message that has to be logged.

log

public void log(java.lang.String message,
                java.lang.Object param1)
Logs the message if log is switched on and severity INFO_LEVEL will be logged. The severity for this message is INFO_LEVEL.

Parameters:
message - The message that has to be logged. See java.text.MessageFormat for the format of this string.
param1 - The first parameter for the message. See java.text.MessageFormat .
See Also:
for further details.

log

public void log(java.lang.String message,
                java.lang.Object param1,
                java.lang.Object param2)
Logs the message if log is switched on and severity INFO_LEVEL will be logged. The severity for this message is INFO_LEVEL.

Parameters:
message - The message that has to be logged. See java.text.MessageFormat for the format of this string.
param1 - The first parameter for the message. See java.text.MessageFormat .
param2 - The second parameter for the message. See java.text.MessageFormat .
See Also:
for further details.

log

public void log(java.lang.String message,
                java.lang.Object param1,
                java.lang.Object param2,
                java.lang.Object param3)
Logs the message if log is switched on and severity INFO_LEVEL will be logged. The severity for this message is INFO_LEVEL.

Parameters:
message - The message that has to be logged. See java.text.MessageFormat for the format of this string.
param1 - The first parameter for the message. See java.text.MessageFormat .
param2 - The second parameter for the message. See java.text.MessageFormat .
param3 - The third parameter for the message. See java.text.MessageFormat .
See Also:
for further details.

log

public void log(java.lang.String message,
                java.lang.Object[] params)
Logs the message if log is switched on and severity INFO_LEVEL will be logged. The severity for this message is INFO_LEVEL.

Parameters:
message - The message that has to be logged. See java.text.MessageFormat for the format of this string.
params - The parameter list for the message. See java.text.MessageFormat .
See Also:
for further details.

logException

public void logException(int severity,
                         java.lang.String message,
                         java.lang.Object[] params,
                         java.lang.Throwable t,
                         boolean printStackTrace)
Logs an Exception with the given message if log is switched on. The stacktrace of the exception is logged if the given flag is true .

Parameters:
severity - The severity for this message.
message - The message that has to be logged. See java.text.MessageFormat for the format of this string.
params - The parameter list for the message. See java.text.MessageFormat .
t - The Throwable that has to be logged.
printStackTrace - Indicates if the stack trace should be printed too.
See Also:
for further details.

logException

public void logException(int severity,
                         java.lang.String message,
                         java.lang.Throwable t,
                         boolean printStackTrace)
Logs an Exception with the given message if log is switched on. The stacktrace of the exception is logged if the given flag is true .

Parameters:
severity - The severity for this message.
message - The message that has to be logged.
t - The Throwable that has to be logged.
printStackTrace - Indicates if the stack trace should be printed too.

logException

public void logException(java.lang.String message,
                         java.lang.Throwable t,
                         boolean printStackTrace)
Logs an Exception with the given message if log is switched on. The stacktrace of the exception is logged if the given flag is true . The message will be logged with severity ERROR_LEVEL.

Parameters:
message - The message that has to be logged.
t - The Throwable that has to be logged.
printStackTrace - Indicates if the stack trace should be printed too.

logException

public void logException(int severity,
                         java.lang.Throwable t)
Logs an Exception without any additional message if log is switched on. The stacktrace of the exception is logged.

Parameters:
severity - The severity for this message.
t - The Throwable that has to be logged.

logException

public void logException(int severity,
                         java.lang.Throwable t,
                         boolean printStackTrace)
Logs an Exception without any additional message if log is switched on. The stacktrace of the exception is logged if the given flag is true .

Parameters:
severity - The severity for this message.
t - The Throwable that has to be logged.
printStackTrace - Indicates if the stack trace should be printed too.

logException

public void logException(java.lang.Throwable t)
Logs an Exception without any additional message if log is switched on. The stacktrace of the exception is logged. The message will be logged with severity ERROR_LEVEL.

Parameters:
t - The Throwable that has to be logged.

logException

public void logException(java.lang.Throwable t,
                         boolean printStackTrace)
Logs an Exception without any additional message if log is switched on. The stacktrace of the exception is logged. The message will be logged with severity ERROR_LEVEL.

Parameters:
t - The Throwable that has to be logged.
printStackTrace - Indicates if the stack trace should be printed too.

switchOn

public abstract boolean switchOn(boolean on)
Turns the log on or off. Returns true iff the change was successful.

Parameters:
on - Description of the Parameter
Returns:
Description of the Return Value

reset

public void reset()
Resets the log. If the log was switched on it will be switched on after reset.


isLogging

public abstract boolean isLogging(int severity)
Returns true iff the given log severity will be logged.

Parameters:
severity - The log severity that has to be checked.
Returns:
true iff the given log severity will be logged.

logFileContent

public void logFileContent(int severity,
                           java.io.File file,
                           java.lang.String encoding)
Logs the content of a file into the log file if log is switched on and the trace level is less or equal the current trace level.

Parameters:
severity - The severity for this message.
file - The file that has to be logged.
encoding - The encoding that should be used to read the file

getWriter

public java.io.Writer getWriter(int severity,
                                java.lang.String message)
Writes a given message to trace (with prefix "Start: ") and returns current log writer. Returns null if trace is disabled.

Parameters:
severity - The severity for this message.
message - A message that will be traced.
Returns:
null if trace is off otherwise current log writer is returned.

releaseWriter

public void releaseWriter(int severity,
                          java.lang.String message)
Writes a given message to trace (with prefix "End: ") and updates internal status.

Parameters:
severity - The severity for this message.
message - A message that will be traced.

read

public java.util.Vector read()
Reads the trace file and returns an String - Enumeration of the log file lines. Returns an empty vector if the trace file is empty or if there are any exceptions while reading the trace file. This method alsoe reads the content of backup files if available.

Returns:
String - Enumeration of the log file lines. Returns an empty vector if the trace file is empty or if there are any exceptions while reading the trace file.

getLogContentAsStream

public java.io.InputStream getLogContentAsStream()
Returns an input stream with the log content. Returns null if there is no log content or if this feature is not supported by corresponding log writer.

Returns:
Input stream with log content. null if there is no content or if log writer does not provide this feature.

getEffectiveSeverity

public abstract int getEffectiveSeverity()
Gets the current log level of the log

Returns:
The current log severity.

setEffectiveSeverity

public abstract void setEffectiveSeverity(int severity)
Gets the current log level of the log

Parameters:
severity - the new log severity

isOn

public abstract boolean isOn()
Gets the current activation state of the log.

Returns:
Returns true iff log is on.

refresh

public abstract void refresh()
Do not use this method. This method is used be the framework only. This method should be called if the configuration of the log has been changed via Mobile Engine configuration or at startup.


getComponent

public java.lang.String getComponent()
Gets the component name for this log instance.

Returns:
the component name. Returns "Unknown" iff componentname is not set.

getLogWriter

protected abstract LogWriter getLogWriter()
Returns the LogWriter instance of this log.

Returns:
The LogWriter instance of this log.

setLogWriter

protected abstract void setLogWriter(LogWriter newLogWriter)
Sets the LogWriter instance. Before setting a new LogWriter the old LogWriter instance will be switched off. If the given value is null or it is not an instance of LogWriter an IllegalArgumentException will be thrown and the old log writes resists.

Parameters:
newLogWriter - The new LogWriter instance

readConfiguration

protected abstract void readConfiguration(java.lang.String logName)
Reads the configuration for the given log. If there is no entry in the configuration these default values will be used:

Parameters:
logName - The name of the log.

writeConfiguration

protected void writeConfiguration(java.lang.String logName,
                                  boolean userdependant)
Writes the configuration for the given log. After that the log writer is called to save its configuration. The following entries will be saved.

Parameters:
logName - The name of the log.
userdependant - Description of the Parameter

setOn

protected abstract void setOn(boolean on)
Sets the current activation state of the log.

Parameters:
on - The new on value

getLogWriterClassname

protected abstract java.lang.String getLogWriterClassname()
Gets the configured filename / path of the log.

Returns:
Returns the configured filename / path information of the log.

setComponent

protected void setComponent(java.lang.String componentname)
Sets the component name for this instance.

Parameters:
componentname -

getLogLevelName

protected java.lang.String getLogLevelName(int logLevel)
Gets the logLevelName attribute of the AbstractLogging object

Parameters:
logLevel - Description of the Parameter
Returns:
The logLevelName value


Copyright © 2005 SAP AG. All Rights Reserved.