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

java.lang.Object
  extended bycom.sap.ip.me.api.logging.DefaultFileLogWriter
All Implemented Interfaces:
com.sap.ip.me.api.logging.LogContentStreamSupport, LogWriter

public class DefaultFileLogWriter
extends java.lang.Object
implements LogWriter, com.sap.ip.me.api.logging.LogContentStreamSupport

Default file log writer implementation for Mobile Infrastructure. All messages will be logged into a trace file that can be configured in the MobileEngine.config file. Further on the maximum log filesize can be configured.

Since:
MI 2.5
Author:
SAP

Field Summary
protected static java.lang.String LOG_FILENAME_SUFFIX
          The filename / path suffix of a Mobile Infrastructure log configuration
protected static java.lang.String LOG_MAX_VIEWABLE_SIZE
          The value behind this key determines the maximum size that can be displayed in UI.
protected static java.lang.String LOG_MAXSIZE_SUFFIX
          The maximum (file) size suffix of a Mobile Infrastructure log configuration
 
Constructor Summary
DefaultFileLogWriter()
           
 
Method Summary
 java.util.Vector getLogContent()
          Returns a vector with String objects.
 java.io.InputStream getLogContentAsStream()
          Gets input stream with 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 file.
 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.
 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 file if log writer is switched on.
 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 if log writer is switched on.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG_FILENAME_SUFFIX

protected static final java.lang.String LOG_FILENAME_SUFFIX
The filename / path suffix of a Mobile Infrastructure log configuration

See Also:
Constant Field Values

LOG_MAX_VIEWABLE_SIZE

protected static final java.lang.String LOG_MAX_VIEWABLE_SIZE
The value behind this key determines the maximum size that can be displayed in UI.

See Also:
Constant Field Values

LOG_MAXSIZE_SUFFIX

protected static final java.lang.String LOG_MAXSIZE_SUFFIX
The maximum (file) size suffix of a Mobile Infrastructure log configuration

See Also:
Constant Field Values
Constructor Detail

DefaultFileLogWriter

public DefaultFileLogWriter()
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 file if log writer is switched on.

Specified by:
writeln in interface LogWriter
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:
<{java.text.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 if log writer is switched on. Depending of the printStacktrace parameter a stack trace of the Exception will be logged too.

Specified by:
writeln in interface LogWriter
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:
<{java.text.MessageFormat}>

reset

public boolean reset()
Resets the log. Deletes the log file and the backup log file. If log was switched on it will be switched on after reset.

Specified by:
reset in interface LogWriter
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 file.

Specified by:
logFileContent in interface LogWriter
Parameters:
severity - The severity for this message
component - The component that logs 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 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.

Specified by:
getWriter in interface LogWriter
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.

Specified by:
releaseWriter in interface LogWriter
Parameters:
severity - The severity for this message.
message - A message that will be traced.

switchOn

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

Specified by:
switchOn in interface LogWriter
Parameters:
on - true iff the log should be switched on. The log writer handles multiple calls of this method.
Returns:
Returns true if switch was successful.

getLogContent

public java.util.Vector getLogContent()
Returns a vector with String objects. Every object represents a line of the log file. If there is no log file available an empty vector is returned.

Specified by:
getLogContent in interface LogWriter
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.

Specified by:
initialize in interface LogWriter
Parameters:
configurationPrefix - The configuration prefix that should be used to initialize the log writer.

setPrintProlog

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

Specified by:
setPrintProlog in interface LogWriter
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.

Specified by:
setPrintAppendix in interface LogWriter
Parameters:
printAppendix - true if the log appendix should be written.

getLogContentAsStream

public java.io.InputStream getLogContentAsStream()
Gets input stream with log content.

Specified by:
getLogContentAsStream in interface com.sap.ip.me.api.logging.LogContentStreamSupport
Returns:
The logContentAsStream value


Copyright © 2005 SAP AG. All Rights Reserved.