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:
We recommend setting log level to ERROR for shipping code. Log level can be set by calling: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");
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
. To be notified when the upload is complete, implementLogging.uploadLog
, and add that to the listener list by callingLogging.UploadListener
.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:
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.DEFAULT
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.LAST
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.MERGE
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
-
Method Summary
Modifier and Type Method Description static void
initialize(@NonNull() Context context)
Initializes SAP logging. static void
initialize(@NonNull() Context context, @NonNull() Logging.ConfigurationBuilder builder)
Initializes SAP logging with configurations. static boolean
isInitialized()
Returns whether the logger has been initialized, and it has not been reset since then. static Logging.ConfigurationBuilder
getConfigurationBuilder()
static void
setConfigurationBuilder(@Nullable() Logging.ConfigurationBuilder builder)
Set logging configuration object before initializing the service. static Logger
getRootLogger()
Get the logback root logger. static boolean
deleteAllLogFiles()
Delete all files used to log. static String
getConsoleLoggerPattern()
Get the layout pattern used in the Android console. static void
setConsoleLoggerPattern(@NonNull() String pattern)
Set the layout pattern used in the Android console. static void
addLogUploadListener(@NonNull() Logging.UploadListener listener)
static void
addUploadListener(@NonNull() Logging.UploadListener listener)
Register a listener for log upload events. static void
removeLogUploadListener(@NonNull() Logging.UploadListener listener)
static void
removeUploadListener(@NonNull() Logging.UploadListener listener)
Unregister a listener for log upload events. static void
uploadLog(@NonNull() OkHttpClient client, @NonNull() SettingsParameters settingsParameters)
static void
upload(@NonNull() OkHttpClient client, @NonNull() SettingsParameters settingsParameters)
Upload the log to mobile services. static void
upload()
Upload the log to mobile services. static void
uploadLog(@NonNull() OkHttpClient client, @NonNull() SettingsParameters settingsParameters, @NonNull() Logging.UploadType uploadType)
static void
upload(@NonNull() OkHttpClient client, @NonNull() SettingsParameters settingsParameters, @NonNull() Logging.UploadType uploadType)
Upload the log to mobile services. static void
upload(@NonNull() Logging.UploadType uploadType)
Upload the log to mobile services. static boolean
isTaskRunning()
static boolean
hasPendingLog()
Returns true if there is an old log that did get uploaded from a previous upload attempt. static void
cancelUploadLog()
Cancels log upload if an upload is in progress. -
-
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 contextbuilder
- Builder object with initialization parameters
-
isInitialized
static boolean isInitialized()
Returns whether the logger has been initialized, and it has not been reset since then.
- Returns:
true if SAPRollingFileAppender and FixedWindowRollingPolicy are present, otherwise false
-
getConfigurationBuilder
@Nullable() static Logging.ConfigurationBuilder getConfigurationBuilder()
-
setConfigurationBuilder
static void setConfigurationBuilder(@Nullable() Logging.ConfigurationBuilder builder)
Set logging configuration object before initializing the service.
- Parameters:
builder
- Builder object with initialization parameters
-
getRootLogger
@NonNull() static Logger getRootLogger()
Get the logback root logger.
- Returns:
the logback root logger.
-
deleteAllLogFiles
static boolean deleteAllLogFiles()
Delete all files used to log. Logging.initialize must be called before calling deleteAllLogFiles().
- Returns:
false if any of the log files failed to be deleted, otherwise true.
-
getConsoleLoggerPattern
@NonNull() static String getConsoleLoggerPattern()
Get the layout pattern used in the Android console.
See the logback documentation for more information on layout patterns.
- Returns:
the layout pattern used in the Android console.
-
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.
-
addLogUploadListener
@Deprecated() static void addLogUploadListener(@NonNull() Logging.UploadListener listener)
- Parameters:
listener
- a listener for log upload events.
-
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.
-
removeLogUploadListener
@Deprecated() static void removeLogUploadListener(@NonNull() Logging.UploadListener listener)
- Parameters:
listener
- the listener to unregister.
-
removeUploadListener
static void removeUploadListener(@NonNull() Logging.UploadListener listener)
Unregister a listener for log upload events.
- Parameters:
listener
- the listener to unregister.
-
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.
-
isTaskRunning
static boolean isTaskRunning()
-
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.
- Returns:
false if an upload is currently in progress or last call to uploadLog() completed successfully. Otherwise, returns true.
-
cancelUploadLog
static void cancelUploadLog()
Cancels log upload if an upload is in progress.
-
-
-
-