Java
Copied to your clipboardCacheService cacheService = ServiceProvider.getInstance().getCacheService();
Swift
Copied to your clipboardprivate var cacheService: Caching { return ServiceProvider.shared.cacheService }
Java
First, implement a class that conforms to the Logging
interface. Below is an example of a logging service that only prints out messages with a log level of Error.
Copied to your clipboardclass ErrorLogger implements Logging {@Overridepublic void trace(String tag, String message) {}@Overridepublic void debug(String tag, String message) {}@Overridepublic void warning(String tag, String message) {}@Overridepublic void error(String tag, String message) {Log.e("ErrorLogger", message);}}
Next, use the setLoggingService
API of ServiceProvider
to update the logging service used by the SDK.
Copied to your clipboardServiceProvider.getInstance().setLoggingService(new ErrorLogger());
To revert to the default implementation of the LoggingService
, you can set the logging service to nil using setLoggingService
API.
Copied to your clipboardServiceProvider.getInstance().setLoggingService(null);
Swift
First, implement a type that conforms to the Logging protocol, as defined above. Below is an example of a logging service that only prints out messages with a log level of Error
.
Copied to your clipboardclass ErrorLogger: Logging {func log(level: LogLevel, label: String, message: String) {guard level == .error else { return }print("\(label): \(message)")}}
Next, set the loggingService
on the shared ServiceProvider
used by the SDK.
Copied to your clipboardServiceProvider.shared.loggingService = ErrorLogger()
To revert to the default implementation of the LoggingService
, you can set the loggingService to nil.
Copied to your clipboardServiceProvider.shared.loggingService = nil