Package 

Class Logging


  • 
    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: .

    Uploading LogsLogs 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.

    • Method Detail

      • initialize

         static void initialize(Context context)

        Initializes SAP logging.

        Parameters:
        context - The application context
      • initialize

         static void initialize(Context context, 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 callingdeleteAllLogFiles().

      • setConsoleLoggerPattern

         static void setConsoleLoggerPattern(String pattern)

        Set the layout pattern used in the Android console.

        See thelogback documentationfor more information on layout patterns.

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

         static synchronized void addUploadListener(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.
      • configLog

         static void configLog(Context context, Logging.ConfigurationBuilder builder)

        Configures SAP logging.Persists logged information in a rolling log and makes the information available for upload.

        Parameters:
        context - the application context
        builder - logging configuration builder object with initialization parameters
      • uploadLog

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

         static void upload(OkHttpClient client, 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 oldlog is deleted and not uploaded.The upload is executed in the background using an AsyncTask usingAsyncTask.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 oldlog is deleted and not uploaded.The upload is executed in the background using an AsyncTask usingAsyncTask.THREAD_POOL_EXECUTOR.

      • uploadLog

         static void uploadLog(OkHttpClient client, SettingsParameters settingsParameters, 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(OkHttpClient client, SettingsParameters settingsParameters, 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 usingAsyncTask.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(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 usingAsyncTask.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.