Configuring logging
Medallia Experience Orchestration SDK for Android provides an extensible logging configuration API for debug or reporting purposes. The API can be configured to log any combination of Components (features or technical concepts such as Networking or Databases) to log levels (Verbose, Debug, etc). In addition, custom log writers can be added to facilitate reporting if desired (ex. sending errors to Google Console).
onCreate
method of your project's Application
class before the initialization of the SDK.By default, the Medallia Experience Orchestration SDK for Android logs Error and Warn messages for Any component. Below are examples of other logging configurations.
MedalliaMXO:
in the console.Turning all logs on
This is an example of configuring logging to Verbose log level for Any Components of the Medallia Experience Orchestration SDK.
import com.medallia.mxo.logging.MXOLogComponent
import com.medallia.mxo.logging.MXOLogLevel
import com.medallia.mxo.mxoConfigureLogging
mxoConfigureLogging {
levels = setOf(MXOLogLevel.VERBOSE)
components = setOf(MXOLogComponent.ANY)
}
import com.medallia.mxo.MedalliaMXO;
import com.medallia.mxo.logging.MXOLogComponent;
import com.medallia.mxo.logging.MXOLogLevel;
import com.medallia.mxo.logging.MXOLoggingConfiguration;
MXOLoggingConfiguration mxoLoggingConfiguration = new MXOLoggingConfiguration.Builder()
.log(MXOLogLevel.VERBOSE)
.log(MXOLogComponent.ANY)
.build();
MedalliaMXO.setLoggingConfiguration(mxoLoggingConfiguration);
When setting MXOLogComponent
to only Any, all components will be logged in conjunction with the log level.
Turning specific logs on
This is an example of configuring logging to combination of Error and Warn levels for just Networking and Database components of the Medallia Experience Orchestration SDK.
import com.medallia.mxo.logging.MXOLogComponent
import com.medallia.mxo.logging.MXOLogLevel
import com.medallia.mxo.mxoConfigureLogging
mxoConfigureLogging {
levels = MXOLogLevel.ERROR and MXOLogLevel.WARN
components = MXOLogComponent.NETWORKING and MXOLogComponent.DATABASE
}
import com.medallia.mxo.MedalliaMXO;
import com.medallia.mxo.logging.MXOLogComponent;
import com.medallia.mxo.logging.MXOLogLevel;
import com.medallia.mxo.logging.MXOLoggingConfiguration;
MXOLoggingConfiguration mxoLoggingConfiguration = new MXOLoggingConfiguration.Builder()
.log(MXOLogLevel.ERROR)
.log(MXOLogLevel.WARN)
.log(MXOLogComponent.NETWORKING)
.log(MXOLogComponent.DATABASE)
.build();
MedalliaMXO.setLoggingConfiguration(mxoLoggingConfiguration);
When setting a single MXOLogLevel
, the SDK will log any messages of that level and above. The order from the bottom is: Verbose, Debug, Error, Warn, Info, Assert.
Examples:
- Setting Info will log only Info and Assert messages.
Setting Verbose will log all messages.
When setting multiple MXOLogLevel
(s), the SDK will log only messages of those specific levels. As an example, setting Error and Warn will only log message of Error and Warn levels and nothing else.
Using a custom logger
This is an example of using a custom logger.
import com.medallia.mxo.logging.MXOLogComponent
import com.medallia.mxo.logging.MXOLogLevel
import com.medallia.mxo.mxoConfigureLogging
import com.medallia.mxo.logging.MXOLogWriter
mxoConfigureLogging {
levels = setOf(MXOLogLevel.VERBOSE)
components = MXOLogComponent.NETWORKING and MXOLogComponent.DATABASE
logWriters = setOf(CustomLogger())
}
class CustomLogger : MXOLogWriter() {
override fun log(
logLevel: MXOLogLevel,
component: MXOLogComponent,
message: String,
throwable: Throwable?
) {
Log.d("CustomLogger", "Component: ${component.name}\nMessage: $message", throwable)
}
}
import com.medallia.com.MedalliaMXO;
import com.medallia.mxo.logging.MXOLogComponent;
import com.medallia.mxo.logging.MXOLogLevel;
import com.medallia.mxo.logging.MXOLoggingConfiguration;
import com.medallia.mxo.logging.MXOLogWriter;
MXOLoggingConfiguration mxoLoggingConfiguration = new MXOLoggingConfiguration.Builder()
.log(MXOLogLevel.VERBOSE)
.log(MXOLogComponent.NETWORKING)
.log(MXOLogComponent.DATABASE)
.logTo(new CustomLogger())
.build();
MedalliaMXO.setLoggingConfiguration(mxoLoggingConfiguration);
static class CustomLogger implements MXOLogWriter {
@Override
public void log(
@NonNull MXOLogLevel mxoLogLevel,
@NonNull MXOLogComponent mxoLogComponent,
@NonNull String s, @Nullable Throwable throwable
) {
Log.d("Custom", s);
}
}
Turning logs for the MXO SDK initialization process on
The Medallia Experience Orchestration SDK performs initialization processes in an Android Content Provider which is instantiated before the Application is created. This means the log configuration API cannot be invoked before the Orchestration SDK has finished its initialization process. To turn on logging for the initialization process of the Orchestration SDK a meta data element must be added to the android manifest. If the metadata element is not set no logging is configured.
Metadata Info
:
name
: com.medallia.mxo.InitLogLevel
value
: Comma separated list of com.medallia.mxo.logging.MXOLogLevel
This is an example for logging Verbose and above logs.
<application>
<!--Other application elements-->
<meta-data
android:name="com.medallia.mxo.InitLogLevel"
android:value="VERBOSE" />
</application>
The com.medallia.mxo.InitLogLevel
AndroidManifest.xml
metadata value is only honored for the Medallia Experience Orchestration SDK initialization process. After initialization has finished, the logging configuration reverts to a default configuration mentioned above. If more logging is desired then use the logging configuration APIs to turn on logging as shown above.
Turning all logs off
This is an example of turning the Medallia Experience Orchestration logging off.
import com.medallia.mxo.logging.MXOLogComponent
import com.medallia.mxo.logging.MXOLogLevel
import com.medallia.mxo.mxoConfigureLogging
mxoConfigureLogging {
levels = setOf(MXOLogLevel.NONE)
components = setOf(MXOLogComponent.NONE)
}
import com.medallia.mxo.MedalliaMXO;
import com.medallia.mxo.logging.MXOLogComponent;
import com.medallia.mxo.logging.MXOLogLevel;
import com.medallia.mxo.logging.MXOLoggingConfiguration;
MXOLoggingConfiguration mxoLoggingConfiguration = new MXOLoggingConfiguration.Builder()
.log(MXOLogLevel.NONE)
.log(MXOLogComponent.NONE)
.build();
MedalliaMXO.setLoggingConfiguration(mxoLoggingConfiguration);