SDMLogger

The library supports logging via its ISDMLogger interface and provides SDMLogger as an implementation of this interface.

List of Features

  • Provides a common interface for handling log messages across the library
  • Extends Android's standard logging facility, while keeps method signatures compatible
  • Provides facility to store log data
  • Provides filterable log retrieval by severity, tag, timestamp (from-to), process id and by correlation id

Technical Details

The interface is similar to Android’s standard logging facility (android.util.Log). Logging does not support security and handling sensitive data. It is the responsibility of the applications to handle these requirements. Logging supports retrieving the log data for persistence or other purposes. SDMLogger also implements the ISDMPersistable interface to make the log data persistable. A log header can be set by the application including the following fields:
  • Operating System version
  • App name
  • App Version
  • 3rd Party product versions (for example, SQLlite)
  • Hardware version
  • User
  • Timezone
  • Language
  • SUP/SAP NetWeaver Gateway URL

The SDMConnectivity sets the User, Language and SUP/SAP NetWeaver Gateway URL fields. SDMLogger stores log entries timestamped, in milliseconds granularity of the time the log method called by the application/library component. It can also clean out log messages below a certain level, or clean out the log completely. A preliminary log rotation support is built in. At every log method call, a check runs and verifies whether the number of messages reaches 10000. If the number of messages is greater or equal to this threshold, a low priority background thread is started to clean out the oldest 200 log entries.

SDMLogger provides line-level location logging with the full class name of the logging class. Location detection is done by call stack evaluation. Therefore, SDMLogger provides location parameter setting for the logging class, where the class can set the location instead of using the detection facility. Log messages are stored only above the predefined logging level, which defaults to ERROR log level.

Log priority constants:
  • PERFORMANCE = 1
  • VERBOSE = 2
  • DEBUG = 3
  • INFO = 4
  • WARN = 5
  • ERROR = 6
  • ASSERT = 7
  • FATAL = 8

Log Methods

public void log(final int level, final String tag, final String msg,
			final Throwable tr, final String location)

Parameters:

level  the log level
msg  The message you would like logged. 
tr  An exception to log  
location  The line-level location of the log source (full class name of the class)

public static int d (String tag, String msg) 
public static int d (String tag, String msg, Throwable tr)
public static int d (String tag, String msg, Throwable tr, String location)
Sends a DEBUG log message and logs the exception.

public static int e (String tag, String msg) 
public static int e (String tag, String msg, Throwable tr) 
public static int e (String tag, String msg, Throwable tr, String location) 
Sends an ERROR log message and logs the exception.

public static int i (String tag, String msg) 
public static int i (String tag, String msg, Throwable tr) 
public static int i (String tag, String msg, Throwable tr, String location) 
Sends an INFO log message and logs the exception.

public static int v (String tag, String msg) 
public static int v (String tag, String msg, Throwable tr) 
public static int v (String tag, String msg, Throwable tr, String location) 
Sends a VERBOSE log message and logs the exception.

public static int w (String tag, Throwable tr) 
public static int w (String tag, String msg) 
public static int w (String tag, String msg, Throwable tr) 
public static int w (String tag, String msg, Throwable tr, String location) 
Sends a WARN log message and logs the exception.

public static int wtf (String tag, Throwable tr)
public static int wtf (String tag, String msg)
public static int wtf (String tag, String msg, Throwable tr)
public static int wtf (String tag, String msg, Throwable tr, String location)
What a Terrible Failure: Reports a condition that should never happen. The error will always be logged at level ASSERT.
SDMLogger (ISDMLogger implementation that the Library provides) also has the following functionality:
public void cleanUp(final int threshold)
Deletes all log entries weaker than the ‘threshold’ priority.

public void terminate()
Completely clears the collected log data.

public Vector<LogEntry> getLogElements(final int threshold)
This method returns the log data, including all log data with level ‘threshold’ or above.

public boolean logsToAndroid()
public void logToAndroid(final boolean doIt)
These methods get and set the property which controls sending the log output to the Android logging facility.

public boolean logsFullLocation() 
public void logFullLocation(boolean logFullLocation)
These methods get and set the property which if full location should be logged automatically based on the current stack trace.
public synchronized String toString()
Returns all log data – including the header – as String.
Sample:
Operating System version: 11
Application name: MyApp
Application version: 1.0.0
3rd-party products: -
Hardware version: Galaxy Tab
User name: DEMO
Timezone: CET-DST
Language: en
Base URL: http://www.sap.com/gateway/or/whatever

2011-06-28 14:30:23.368 WARN	SDMPreferences	com.sap.mobile.lib.sdmconfiguration.SDMPreferences.getPreference(SDMPreferences.java:284)	Deprecated method 'getPreference' has been called.
2011-06-28 14:30:23.468 INFO	SDMPreferences	com.sap.mobile.lib.sdmconfiguration.SDMPreferences.setStringPreference(SDMPreferences.java:244)	Preference 'SAP_APPLICATIONID_HEADER_VALUE' (String) has been changed to MyApp.1.0.0.0 
public Vector<LogEntry> getLogElementsByTag(final String aTag)
public Vector<LogEntry> getLogElementsByTimeStamp(final long start, final long end)
public Vector<LogEntry> getLogElementsByPID(final long PID)
public Vector<LogEntry> getLogElementsByCorrelationId(final String correlationId)

These methods return with a Vector of filtered log entries, filtered by TAG, timestamp (interval), process id and correlation id, respectively.