Class Logging

  • All Implemented Interfaces:

    @Deprecated() 
    public final class Logging
    
                        

    The SAP BTP SDK for Android uses Simple Logging Facade for Java (SLF4J) for its logging API. For further information about SLF4J, see .

    Using SLF4J in your code is straight forward. You get a named logger from the LoggerFactory and then log at the level you need to. For example:

    org.slf4j.Logger log = LoggerFactory.getLogger("com.my.package");
    log.info("info");
    log.warn("warn");
    log.debug("debug");
    log.error("error");
    log.trace("trace");
    
    log.info("info {}", "info");
    log.warn("warn {}", "warn");
    log.debug("debug {}", "debug");
    log.error("error {}", "error");
    log.trace("trace {}", "trace");
    
    We recommend setting log level to ERROR for shipping code. Log level can be set by calling:
    Logging.getRootLogger().setLevel(Level.ERROR);

    You can also set the log level when calling

    Logging.initialize

    SLF4J does not do the actual logging. You need a logging implementation to do that. The SAP BTP SDK for Android uses `logback-android`. For further information, see: .

    Logs can be uploaded to mobile services for later review. To upload the log, call
    Logging.uploadLog
    . To be notified when the upload is complete, implement
    Logging.UploadListener
    , and add that to the listener list by calling
    Logging.addLogUploadListener
    .

    Any messages logged at trace level will be uploaded as path messages. Since 4.0, this is deprecated, please use LoggingService to handle log.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      public enum Logging.UploadType

      Upload types, where:

      DEFAULT
      means, upload the current contents of the log. If there is an old log that did not get uploaded from a previous upload attempt, the old log is deleted and not uploaded.
      LAST
      means, if there is an old log that did get uploaded from a previous upload attempt, upload the old log but do not upload the current contents of the log.
      MERGE
      means, upload the current contents of the log, and if there is an old log that did not get uploaded from a previous upload attempt, also upload the old log. You should use some caution with this choice. If repeated attempts to upload the log with this upload type fail, the application could run out of storage space.
      public class Logging.ConfigurationBuilder

      Builder class to build configuration for

      Logging.initialize()
      .
      public interface Logging.UploadListener

      Listener used to dispatch log upload events.

      public class Logging.UploadWorker
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Constructor Detail

    • Method Detail

      • initialize

         static void initialize(@NonNull() Context context)

        Initializes SAP logging.

        Parameters:
        context - The application context
      • initialize

         static void initialize(@NonNull() Context context, @NonNull() Logging.ConfigurationBuilder builder)

        Initializes SAP logging with configurations.

        Parameters:
        context - The application context
        builder - Builder object with initialization parameters
      • isInitialized

         static boolean isInitialized()

        Returns whether the logger has been initialized, and it has not been reset since then.

      • getRootLogger

        @NonNull() static Logger getRootLogger()

        Get the logback root logger.

      • deleteAllLogFiles

         static boolean deleteAllLogFiles()

        Delete all files used to log. Logging.initialize must be called before calling deleteAllLogFiles().

      • setConsoleLoggerPattern

         static void setConsoleLoggerPattern(@NonNull() String pattern)

        Set the layout pattern used in the Android console.

        See the logback documentation for more information on layout patterns.

        Parameters:
        pattern - the layout pattern to use in the Android console.
      • addUploadListener

         static void addUploadListener(@NonNull() Logging.UploadListener listener)

        Register a listener for log upload events. Events will be triggered on the main thread.

        Parameters:
        listener - a listener for log upload events.
      • uploadLog

        @Deprecated() static void uploadLog(@NonNull() OkHttpClient client, @NonNull() SettingsParameters settingsParameters)
        Parameters:
        client - Client that has the mobile services session already established.
        settingsParameters - The application's setting parameters.
      • upload

         static void upload(@NonNull() OkHttpClient client, @NonNull() SettingsParameters settingsParameters)

        Upload the log to mobile services. The log will be purged as part of the upload.

        If there is an old log that did not get uploaded from a previous upload attempt, the old log is deleted and not uploaded. The upload is executed in the background using an AsyncTask using AsyncTask.THREAD_POOL_EXECUTOR.

        Parameters:
        client - Client that has the mobile services session already established.
        settingsParameters - The application's setting parameters.
      • upload

         static void upload()

        Upload the log to mobile services. The log will be purged as part of the upload.

        If there is an old log that did not get uploaded from a previous upload attempt, the old log is deleted and not uploaded. The upload is executed in the background using an AsyncTask using AsyncTask.THREAD_POOL_EXECUTOR.

      • uploadLog

        @Deprecated() static void uploadLog(@NonNull() OkHttpClient client, @NonNull() SettingsParameters settingsParameters, @NonNull() Logging.UploadType uploadType)
        Parameters:
        client - Client that has the mobile services session already established.
        settingsParameters - The application's setting parameters.
        uploadType - The type of upload to perform.
      • upload

         static void upload(@NonNull() OkHttpClient client, @NonNull() SettingsParameters settingsParameters, @NonNull() Logging.UploadType uploadType)

        Upload the log to mobile services. The log will be purged as part of the upload. The upload is executed in the background using an AsyncTask using AsyncTask.THREAD_POOL_EXECUTOR.

        Parameters:
        client - Client that has the mobile services session already established.
        settingsParameters - The application's setting parameters.
        uploadType - The type of upload to perform.
      • upload

         static void upload(@NonNull() Logging.UploadType uploadType)

        Upload the log to mobile services. The log will be purged as part of the upload. The upload is executed in the background using an AsyncTask using AsyncTask.THREAD_POOL_EXECUTOR.

        Parameters:
        uploadType - The type of upload to perform.
      • hasPendingLog

         static boolean hasPendingLog()

        Returns true if there is an old log that did get uploaded from a previous upload attempt. If an upload is currently in progress false is returned.

      • cancelUploadLog

         static void cancelUploadLog()

        Cancels log upload if an upload is in progress.