com.sap.ip.me.api.logging
Interface LogWriter

All Known Implementing Classes:
DefaultFileLogWriter, DefaultSystemLogWriter

public interface LogWriter

Interface for Mobile Infrastructure log writers. If you want to use your own log writer you have to implement this interface. After that you can configure the Mobile Infrastructure to use your log writer implementation instead of the default log writers of the Mobile Infrastructure. The default log writers for AppLog and Trace are instances of DefaultFileLogWriter. You can change it for example by editing the MobileEngine.config file in settings folder of the Mobile Infrastructure installation.
The default settings are:
MobileEngine.Trace.Implementation = com.sap.ip.me.api.logging.DefaultFileLogWriter
MobileEngine.AppLog.Implementation = com.sap.ip.me.api.logging.DefaultFileLogWriter

Example:
Set DefaultSystemLogWriter for AppLog and com.mycompany.mi.MyLogWriter for Trace:
Open the settings\MobileEngine.config file from your MI installation. If there are already lines for the following keys edit the lines or append the following two lines to the config file:
MobileEngine.Trace.Implementation = com.mycompany.mi.MyLogWriter
MobileEngine.AppLog.Implementation = com.sap.ip.me.api.logging.DefaultSystemLogWriter
Take care that the jar file that contains the custom log writer is in the class path (contained in listOfJars.txt). Restart the Mobile Infrastructure.

Since:
MI 2.5
Author:
SAP

Method Summary
 java.util.Vector getLogContent()
          Returns a line vector of the log content.
 java.io.Writer getWriter(int severity, java.lang.String component, java.lang.String message)
          Writes a given message to trace (with prefix "Start: ") and returns current log writer.
 void initialize(java.lang.String configurationPrefix)
          Initializes the log writer with given configuration prefix.
 void logFileContent(int severity, java.lang.String component, java.io.File file, java.lang.String encoding)
          Logs the content of a file into the log.
 void releaseWriter(int severity, java.lang.String component, java.lang.String message)
          Writes a given message to trace (with prefix "End: ") and updates internal status.
 boolean reset()
          Resets the log (delete the log file, empty the internal representation of the log).
 void setPrintAppendix(boolean printAppendix)
          Sets the flag if the log appendix should be written everytime the log is switched off.
 void setPrintProlog(boolean printProlog)
          Sets the flag if the log prolog should be written everytime the log is switched on.
 boolean switchOn(boolean on)
          Switch the log writer on or off.
 void writeln(int severity, java.lang.String component, java.lang.String message, java.lang.Object[] params)
          Formats the message and writes it into the log.
 void writeln(int severity, java.lang.String component, java.lang.String message, java.lang.Object[] params, java.lang.Throwable t, boolean printStacktrace)
          Formats the message and writes it into the log.
 

Method Detail

writeln

public void writeln(int severity,
                    java.lang.String component,
                    java.lang.String message,
                    java.lang.Object[] params)
Formats the message and writes it into the log.

Parameters:
severity - The severity for this message.
component - The component that logs 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:
MessageFormat

writeln

public void writeln(int severity,
                    java.lang.String component,
                    java.lang.String message,
                    java.lang.Object[] params,
                    java.lang.Throwable t,
                    boolean printStacktrace)
Formats the message and writes it into the log. Depending of the printStacktrace parameter a stack trace of the Exception will be logged too.

Parameters:
severity - The severity for this message.
component - The component that logs 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 - true iff the stacktrace should be logged.
See Also:
MessageFormat

switchOn

public boolean switchOn(boolean on)
Switch the log writer on or off.

Parameters:
on - true iff the log should be switched on. The log writer has to handle multiple calls of this method.
Returns:
Returns true if switch was successful.

reset

public boolean reset()
Resets the log (delete the log file, empty the internal representation of the log). If log was switched on it will be switched on after reset.

Returns:
Returns true iff reset was successful

logFileContent

public void logFileContent(int severity,
                           java.lang.String component,
                           java.io.File file,
                           java.lang.String encoding)
Logs the content of a file into the log.

Parameters:
severity - The log severity for this file.
component - The component that logs this file.
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 component,
                                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 component,
                          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.

getLogContent

public java.util.Vector getLogContent()
Returns a line vector of the log content. Does not return null , returns empty vector instead.

Returns:
A vector of lines of the log.

initialize

public void initialize(java.lang.String configurationPrefix)
Initializes the log writer with given configuration prefix. DO NOT call this method . This method is called by the Mobile Infrastructure framework after creation of AppLog or Trace instances.

Parameters:
configurationPrefix - The configuration prefix that should be used to initialize the log writer (e.g. MobileEngine.Trace)

setPrintProlog

public void setPrintProlog(boolean printProlog)
Sets the flag if the log prolog should be written everytime the log is switched on.

Parameters:
printProlog - true if the log prolog should be written.

setPrintAppendix

public void setPrintAppendix(boolean printAppendix)
Sets the flag if the log appendix should be written everytime the log is switched off.

Parameters:
printAppendix - true if the log appendix should be written.


Copyright © 2005 SAP AG. All Rights Reserved.