diff --git a/embrace-android-fcm/src/main/java/io/embrace/android/embracesdk/fcm/swazzle/callback/com/android/fcm/FirebaseSwazzledHooks.java b/embrace-android-fcm/src/main/java/io/embrace/android/embracesdk/fcm/swazzle/callback/com/android/fcm/FirebaseSwazzledHooks.java index 4825005231..5b643ff97a 100644 --- a/embrace-android-fcm/src/main/java/io/embrace/android/embracesdk/fcm/swazzle/callback/com/android/fcm/FirebaseSwazzledHooks.java +++ b/embrace-android-fcm/src/main/java/io/embrace/android/embracesdk/fcm/swazzle/callback/com/android/fcm/FirebaseSwazzledHooks.java @@ -1,7 +1,6 @@ package io.embrace.android.embracesdk.fcm.swazzle.callback.com.android.fcm; -import static io.embrace.android.embracesdk.logging.InternalStaticEmbraceLogger.logDebug; -import static io.embrace.android.embracesdk.logging.InternalStaticEmbraceLogger.logError; +import static io.embrace.android.embracesdk.logging.InternalStaticEmbraceLogger.logger; import androidx.annotation.NonNull; @@ -19,10 +18,10 @@ private FirebaseSwazzledHooks() { @SuppressWarnings("MethodNameCheck") @InternalApi public static void _onMessageReceived(@NonNull RemoteMessage message) { - logDebug("Embrace received push notification message"); + logger.logDebug("Embrace received push notification message"); if (!Embrace.getInstance().isStarted()) { - logError("Embrace received push notification data before the SDK was started"); + logger.logError("Embrace received push notification data before the SDK was started"); return; } @@ -38,21 +37,21 @@ private static void handleRemoteMessage(@NonNull RemoteMessage message) { try { messageId = message.getMessageId(); } catch (Exception e) { - logError("Failed to capture FCM messageId", e); + logger.logError("Failed to capture FCM messageId", e); } String topic = null; try { topic = message.getFrom(); } catch (Exception e) { - logError("Failed to capture FCM topic", e); + logger.logError("Failed to capture FCM topic", e); } Integer messagePriority = null; try { messagePriority = message.getPriority(); } catch (Exception e) { - logError("Failed to capture FCM message priority", e); + logger.logError("Failed to capture FCM message priority", e); } RemoteMessage.Notification notification = null; @@ -60,7 +59,7 @@ private static void handleRemoteMessage(@NonNull RemoteMessage message) { try { notification = message.getNotification(); } catch (Exception e) { - logError("Failed to capture FCM RemoteMessage Notification", e); + logger.logError("Failed to capture FCM RemoteMessage Notification", e); } String title = null; @@ -70,19 +69,19 @@ private static void handleRemoteMessage(@NonNull RemoteMessage message) { try { title = notification.getTitle(); } catch (Exception e) { - logError("Failed to capture FCM title", e); + logger.logError("Failed to capture FCM title", e); } try { body = notification.getBody(); } catch (Exception e) { - logError("Failed to capture FCM body", e); + logger.logError("Failed to capture FCM body", e); } try { notificationPriority = notification.getNotificationPriority(); } catch (Exception e) { - logError("Failed to capture FCM notificationPriority", e); + logger.logError("Failed to capture FCM notificationPriority", e); } } @@ -91,20 +90,20 @@ private static void handleRemoteMessage(@NonNull RemoteMessage message) { try { Embrace.getInstance().logPushNotification( - title, - body, - topic, - messageId, - notificationPriority, - messagePriority, - hasNotification, - hasData + title, + body, + topic, + messageId, + notificationPriority, + messagePriority, + hasNotification, + hasData ); } catch (Exception e) { - logError("Failed to log push Notification", e); + logger.logError("Failed to log push Notification", e); } } catch (Exception e) { - logError("Push Notification Error", e); + logger.logError("Push Notification Error", e); } } } diff --git a/embrace-android-okhttp3/src/main/java/io/embrace/android/embracesdk/okhttp3/swazzle/callback/okhttp3/OkHttpClient.java b/embrace-android-okhttp3/src/main/java/io/embrace/android/embracesdk/okhttp3/swazzle/callback/okhttp3/OkHttpClient.java index 98a19ac169..8e2444c7f9 100644 --- a/embrace-android-okhttp3/src/main/java/io/embrace/android/embracesdk/okhttp3/swazzle/callback/okhttp3/OkHttpClient.java +++ b/embrace-android-okhttp3/src/main/java/io/embrace/android/embracesdk/okhttp3/swazzle/callback/okhttp3/OkHttpClient.java @@ -1,9 +1,10 @@ package io.embrace.android.embracesdk.okhttp3.swazzle.callback.okhttp3; +import static io.embrace.android.embracesdk.logging.InternalStaticEmbraceLogger.logger; + import java.util.List; import io.embrace.android.embracesdk.annotation.InternalApi; -import io.embrace.android.embracesdk.logging.InternalStaticEmbraceLogger; import io.embrace.android.embracesdk.okhttp3.EmbraceOkHttp3ApplicationInterceptor; import io.embrace.android.embracesdk.okhttp3.EmbraceOkHttp3NetworkInterceptor; import okhttp3.Interceptor; @@ -34,13 +35,13 @@ private Builder() { */ @SuppressWarnings("MethodNameCheck") public static void _preBuild(okhttp3.OkHttpClient.Builder thiz) { - InternalStaticEmbraceLogger.logDebug("Embrace OkHTTP Wrapper; onPrebuild"); + logger.logDebug("Embrace OkHTTP Wrapper; onPrebuild"); addEmbraceInterceptors(thiz); } @SuppressWarnings("MethodNameCheck") public static void _constructorOnPostBody(okhttp3.OkHttpClient.Builder thiz) { - InternalStaticEmbraceLogger.logDebug("Embrace OkHTTP Wrapper; onPostBody"); + logger.logDebug("Embrace OkHTTP Wrapper; onPostBody"); addEmbraceInterceptors(thiz); } @@ -51,17 +52,16 @@ public static void _constructorOnPostBody(okhttp3.OkHttpClient.Builder thiz) { */ private static void addEmbraceInterceptors(okhttp3.OkHttpClient.Builder thiz) { try { - InternalStaticEmbraceLogger.logDebug("Embrace OkHTTP Wrapper;" - + " Adding interceptors"); + logger.logDebug("Embrace OkHTTP Wrapper; Adding interceptors"); addInterceptor(thiz.interceptors(), new EmbraceOkHttp3ApplicationInterceptor()); addInterceptor(thiz.networkInterceptors(), new EmbraceOkHttp3NetworkInterceptor()); } catch (NoSuchMethodError exception) { // The customer may be overwriting OkHttpClient with their own implementation, and some of the // methods we use are missing. - InternalStaticEmbraceLogger.logError("Altered OkHttpClient implementation, could not add OkHttp interceptor. ", + logger.logError("Altered OkHttpClient implementation, could not add OkHttp interceptor. ", exception); } catch (Exception exception) { - InternalStaticEmbraceLogger.logError("Could not add OkHttp interceptor. ", exception); + logger.logError("Could not add OkHttp interceptor. ", exception); } } @@ -76,7 +76,7 @@ private static void addInterceptor(List interceptors, if (interceptors != null && !containsInstance(interceptors, interceptor.getClass())) { interceptors.add(0, interceptor); } else { - InternalStaticEmbraceLogger.logDebug( + logger.logDebug( "Not adding interceptor [" + interceptor.getClass().getSimpleName() + "]" ); } @@ -94,7 +94,7 @@ private static boolean containsInstance(List elementsList, Class clazz) { for (T classInstance : elementsList) { if (clazz.isInstance(classInstance)) { - InternalStaticEmbraceLogger.logDebug( + logger.logDebug( "[" + clazz.getSimpleName() + "] already present in list" ); return true; diff --git a/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/features/AeiFeatureTest.kt b/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/features/AeiFeatureTest.kt index deeb92d304..4bd8ef45cd 100644 --- a/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/features/AeiFeatureTest.kt +++ b/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/features/AeiFeatureTest.kt @@ -11,7 +11,6 @@ import io.embrace.android.embracesdk.IntegrationTestRule import io.embrace.android.embracesdk.recordSession import io.mockk.every import io.mockk.mockk -import java.io.InputStream import org.junit.Assert.assertEquals import org.junit.Rule import org.junit.Test diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/EmbraceAutomaticVerification.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/EmbraceAutomaticVerification.kt index 931d21a7cc..2f8a014511 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/EmbraceAutomaticVerification.kt +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/EmbraceAutomaticVerification.kt @@ -9,7 +9,7 @@ import android.os.Handler import android.os.Looper import android.widget.Toast import io.embrace.android.embracesdk.logging.InternalEmbraceLogger -import io.embrace.android.embracesdk.logging.InternalStaticEmbraceLogger +import io.embrace.android.embracesdk.logging.InternalStaticEmbraceLogger.logger import io.embrace.android.embracesdk.samples.AutomaticVerificationChecker import io.embrace.android.embracesdk.samples.VerificationActions import io.embrace.android.embracesdk.samples.VerifyIntegrationException @@ -61,7 +61,7 @@ internal class EmbraceAutomaticVerification( private const val EMBRACE_CONTACT_EMAIL = "support@embrace.io" private const val VERIFY_INTEGRATION_DELAY = 200L private const val ON_FOREGROUND_TIMEOUT = 5000L - internal val instance = EmbraceAutomaticVerification(logger = InternalStaticEmbraceLogger.logger) + internal val instance = EmbraceAutomaticVerification(logger = logger) } fun verifyIntegration() { diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/EmbraceSamples.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/EmbraceSamples.kt index b95c75f442..98ca0aec00 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/EmbraceSamples.kt +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/EmbraceSamples.kt @@ -1,7 +1,7 @@ package io.embrace.android.embracesdk import io.embrace.android.embracesdk.annotation.InternalApi -import io.embrace.android.embracesdk.logging.InternalStaticEmbraceLogger +import io.embrace.android.embracesdk.logging.InternalStaticEmbraceLogger.logger import io.embrace.android.embracesdk.samples.EmbraceCrashSamples /** @@ -15,7 +15,7 @@ import io.embrace.android.embracesdk.samples.EmbraceCrashSamples public object EmbraceSamples { private val embraceCrashSamples = EmbraceCrashSamples - private val embraceAutomaticVerification = EmbraceAutomaticVerification(logger = InternalStaticEmbraceLogger.logger) + private val embraceAutomaticVerification = EmbraceAutomaticVerification(logger = logger) /** * Starts an automatic verification of the following Embrace features: diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/ViewSwazzledHooks.java b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/ViewSwazzledHooks.java index 8d4e27ab49..1b61cba77c 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/ViewSwazzledHooks.java +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/ViewSwazzledHooks.java @@ -1,10 +1,11 @@ package io.embrace.android.embracesdk; +import static io.embrace.android.embracesdk.logging.InternalStaticEmbraceLogger.logger; + import android.util.Pair; import io.embrace.android.embracesdk.annotation.InternalApi; import io.embrace.android.embracesdk.payload.TapBreadcrumb.TapBreadcrumbType; -import io.embrace.android.embracesdk.logging.InternalStaticEmbraceLogger; /** * @hide @@ -35,10 +36,10 @@ static void logOnClickEvent(android.view.View view, TapBreadcrumbType breadcrumb } catch (NoSuchMethodError exception) { // The customer may be overwriting View with their own implementation, and some of the // methods we use are missing. - InternalStaticEmbraceLogger.logError("Could not log onClickEvent. Some methods are missing. ", + logger.logError("Could not log onClickEvent. Some methods are missing. ", exception); } catch (Exception exception) { - InternalStaticEmbraceLogger.logError("Could not log onClickEvent.", exception); + logger.logError("Could not log onClickEvent.", exception); } } diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/network/http/EmbraceHttpPathOverride.java b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/network/http/EmbraceHttpPathOverride.java index 64ebcd5f1c..85e78d9a86 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/network/http/EmbraceHttpPathOverride.java +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/network/http/EmbraceHttpPathOverride.java @@ -1,5 +1,7 @@ package io.embrace.android.embracesdk.internal.network.http; +import static io.embrace.android.embracesdk.logging.InternalStaticEmbraceLogger.logger; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -8,7 +10,6 @@ import java.util.regex.Pattern; import io.embrace.android.embracesdk.annotation.InternalApi; -import io.embrace.android.embracesdk.logging.InternalStaticEmbraceLogger; @InternalApi public class EmbraceHttpPathOverride { @@ -54,31 +55,31 @@ public static String getURLString(@NonNull HttpPathOverrideRequest request, @Nul private static Boolean validatePathOverride(String path) { if (path == null) { - InternalStaticEmbraceLogger.logError("URL relative path cannot be null"); + logger.logError("URL relative path cannot be null"); return false; } - if (path.length() == 0) { - InternalStaticEmbraceLogger.logError("Relative path must have non-zero length"); + if (path.isEmpty()) { + logger.logError("Relative path must have non-zero length"); return false; } if (path.length() > RELATIVE_PATH_MAX_LENGTH) { - InternalStaticEmbraceLogger.logError(String.format(Locale.US, - "Relative path %s is greater than the maximum allowed length of %d. It will be ignored", - path, RELATIVE_PATH_MAX_LENGTH)); + logger.logError(String.format(Locale.US, + "Relative path %s is greater than the maximum allowed length of %d. It will be ignored", + path, RELATIVE_PATH_MAX_LENGTH)); return false; } if (!StandardCharsets.US_ASCII.newEncoder().canEncode(path)) { - InternalStaticEmbraceLogger.logError("Relative path must not contain unicode " + - "characters. Relative path " + path + " will be ignored."); + logger.logError("Relative path must not contain unicode " + + "characters. Relative path " + path + " will be ignored."); return false; } if (!path.startsWith("/")) { - InternalStaticEmbraceLogger.logError("Relative path must start with a /"); + logger.logError("Relative path must start with a /"); return false; } if (!RELATIVE_PATH_PATTERN.matcher(path).matches()) { - InternalStaticEmbraceLogger.logError("Relative path contains invalid chars. " + - "Relative path " + path + " will be ignored."); + logger.logError("Relative path contains invalid chars. " + + "Relative path " + path + " will be ignored."); return false; } diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/network/http/EmbraceHttpUrlConnectionOverride.java b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/network/http/EmbraceHttpUrlConnectionOverride.java index 19ce346f1f..b7c298249d 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/network/http/EmbraceHttpUrlConnectionOverride.java +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/network/http/EmbraceHttpUrlConnectionOverride.java @@ -1,5 +1,7 @@ package io.embrace.android.embracesdk.internal.network.http; +import static io.embrace.android.embracesdk.logging.InternalStaticEmbraceLogger.logger; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -7,8 +9,6 @@ import java.net.MalformedURLException; import java.net.URL; -import io.embrace.android.embracesdk.logging.InternalStaticEmbraceLogger; - class EmbraceHttpUrlConnectionOverride implements HttpPathOverrideRequest { private final HttpURLConnection connection; @@ -30,8 +30,7 @@ public String getOverriddenURL(@NonNull String pathOverride) { return new URL(connection.getURL().getProtocol(), connection.getURL().getHost(), connection.getURL().getPort(), pathOverride + "?" + connection.getURL().getQuery()).toString(); } catch (MalformedURLException e) { - InternalStaticEmbraceLogger.logError("Failed to override path of " + - connection.getURL() + " with " + pathOverride); + logger.logError("Failed to override path of " + connection.getURL() + " with " + pathOverride); return connection.getURL().toString(); } } diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/network/http/EmbraceUrlConnectionDelegate.java b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/network/http/EmbraceUrlConnectionDelegate.java index 6e95e2c3d8..95551eb751 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/network/http/EmbraceUrlConnectionDelegate.java +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/network/http/EmbraceUrlConnectionDelegate.java @@ -1,6 +1,7 @@ package io.embrace.android.embracesdk.internal.network.http; import static io.embrace.android.embracesdk.config.behavior.NetworkSpanForwardingBehavior.TRACEPARENT_HEADER_NAME; +import static io.embrace.android.embracesdk.logging.InternalStaticEmbraceLogger.logger; import android.annotation.TargetApi; import android.os.Build; @@ -34,7 +35,6 @@ import io.embrace.android.embracesdk.Embrace; import io.embrace.android.embracesdk.annotation.InternalApi; -import io.embrace.android.embracesdk.logging.InternalStaticEmbraceLogger; import io.embrace.android.embracesdk.network.EmbraceNetworkRequest; import io.embrace.android.embracesdk.network.http.HttpMethod; import io.embrace.android.embracesdk.utils.exceptions.function.CheckedSupplier; @@ -621,7 +621,7 @@ synchronized void internalLogNetworkCall(long startTime, long endTime, boolean o ); } } catch (Exception e) { - InternalStaticEmbraceLogger.logError("Error logging native network request", e); + logger.logError("Error logging native network request", e); } } } @@ -698,7 +698,7 @@ private void identifyTraceId() { try { traceId = getRequestProperty(embrace.getTraceIdHeader()); } catch (Exception e) { - InternalStaticEmbraceLogger.logDebug("Failed to retrieve actual trace id header. Current: " + traceId); + logger.logDebug("Failed to retrieve actual trace id header. Current: " + traceId); } } } diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/network/http/EmbraceUrlStreamHandlerFactory.java b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/network/http/EmbraceUrlStreamHandlerFactory.java index 8664c999e0..ca628813d3 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/network/http/EmbraceUrlStreamHandlerFactory.java +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/network/http/EmbraceUrlStreamHandlerFactory.java @@ -1,12 +1,12 @@ package io.embrace.android.embracesdk.internal.network.http; +import static io.embrace.android.embracesdk.logging.InternalStaticEmbraceLogger.logger; + import java.net.URLStreamHandler; import java.net.URLStreamHandlerFactory; import java.util.HashMap; import java.util.Map; -import io.embrace.android.embracesdk.logging.InternalStaticEmbraceLogger; - /** * Custom implementation of URLStreamHandlerFactory that is able to return URLStreamHandlers that log network data to * Embrace. @@ -25,7 +25,7 @@ final class EmbraceUrlStreamHandlerFactory implements URLStreamHandlerFactory { handlers.put(PROTOCOL_HTTP, new EmbraceHttpUrlStreamHandler(newUrlStreamHandler(CLASS_HTTP_OKHTTP_STREAM_HANDLER))); handlers.put(PROTOCOL_HTTPS, new EmbraceHttpsUrlStreamHandler(newUrlStreamHandler(CLASS_HTTPS_OKHTTP_STREAM_HANDLER))); } catch (Exception ex) { - InternalStaticEmbraceLogger.logError("Failed initialize EmbraceUrlStreamHandlerFactory", ex); + logger.logError("Failed initialize EmbraceUrlStreamHandlerFactory", ex); } } @@ -35,9 +35,7 @@ static URLStreamHandler newUrlStreamHandler(String className) { } catch (Exception e) { // We catch Exception here instead of the specific exceptions that can be thrown due to a change in the way some // of these exceptions are compiled on different OS versions. - - // TODO: Uncomment this after supporting dependency injection for EmbLogger. - // EmbLogger.logError("Failed to instantiate new URLStreamHandler instance: " + className, e); + logger.logError("Failed to instantiate new URLStreamHandler instance: " + className, e); return null; } } diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/network/http/StreamHandlerFactoryInstaller.java b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/network/http/StreamHandlerFactoryInstaller.java index 513f060855..fd087add1e 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/network/http/StreamHandlerFactoryInstaller.java +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/internal/network/http/StreamHandlerFactoryInstaller.java @@ -1,5 +1,7 @@ package io.embrace.android.embracesdk.internal.network.http; +import static io.embrace.android.embracesdk.logging.InternalStaticEmbraceLogger.logger; + import androidx.annotation.NonNull; import java.lang.reflect.Field; @@ -14,7 +16,6 @@ import javax.net.ssl.HttpsURLConnection; -import io.embrace.android.embracesdk.logging.InternalStaticEmbraceLogger; import io.embrace.android.embracesdk.utils.exceptions.Unchecked; /** @@ -47,10 +48,10 @@ static void registerFactory(Boolean enableRequestSizeCapture) { Object existingFactory = getFactoryField().get(null); if (existingFactory == null) { // No factory is registered, so we can simply register the Embrace factory - InternalStaticEmbraceLogger.logInfo("Registering EmbraceUrlStreamHandlerFactory."); + logger.logInfo("Registering EmbraceUrlStreamHandlerFactory."); URL.setURLStreamHandlerFactory(new EmbraceUrlStreamHandlerFactory()); } else { - InternalStaticEmbraceLogger.logInfo("Existing URLStreamHandlerFactory detected " + + logger.logInfo("Existing URLStreamHandlerFactory detected " + "(" + existingFactory.getClass().getName() + "). Wrapping with Embrace factory " + "to enable network traffic interception."); WrappingFactory wrappingFactory = new WrappingFactory((URLStreamHandlerFactory) existingFactory, enableRequestSizeCapture); @@ -61,11 +62,11 @@ static void registerFactory(Boolean enableRequestSizeCapture) { // Catching Throwable as URL.setURLStreamHandlerFactory throws an Error which we want to // handle, rather than kill the application if we are unable to swap the factory. String msg = "Error during wrapping of UrlStreamHandlerFactory. Will attempt to set the default Embrace factory"; - InternalStaticEmbraceLogger.logWarning(msg, ex); + logger.logWarning(msg, ex); try { URL.setURLStreamHandlerFactory(new EmbraceUrlStreamHandlerFactory()); } catch (Throwable ex2) { - InternalStaticEmbraceLogger.logDebug("Failed to register EmbraceUrlStreamHandlerFactory. Network capture disabled.", ex2); + logger.logDebug("Failed to register EmbraceUrlStreamHandlerFactory. Network capture disabled.", ex2); } } } @@ -135,7 +136,7 @@ public URLStreamHandler createURLStreamHandler(String protocol) { parentHandler = parent.createURLStreamHandler(protocol); } catch (Exception ex) { String msg = "Exception when trying to create stream handler with parent factory for protocol: " + protocol; - InternalStaticEmbraceLogger.logDebug(msg, ex); + logger.logDebug(msg, ex); return new EmbraceUrlStreamHandlerFactory().createURLStreamHandler(protocol); } if (parentHandler == null) { @@ -153,7 +154,7 @@ protected URLConnection openConnection(URL url, Proxy proxy) { return wrapConnection(parentConnection); } catch (Exception ex) { String msg = "Exception when opening connection for protocol: " + protocol + " and URL: " + url; - InternalStaticEmbraceLogger.logDebug(msg, ex); + logger.logDebug(msg, ex); throw Unchecked.propagate(ex); } } @@ -167,7 +168,7 @@ protected URLConnection openConnection(URL url) { return wrapConnection(parentConnection); } catch (Exception ex) { String msg = "Exception when opening connection for protocol: " + protocol + " and URL: " + url; - InternalStaticEmbraceLogger.logDebug(msg, ex); + logger.logDebug(msg, ex); throw Unchecked.propagate(ex); } } @@ -189,7 +190,7 @@ private URLConnection wrapConnection(URLConnection parentConnection) { } } else { // We do not support wrapping this connection type - InternalStaticEmbraceLogger.logDebug("Cannot wrap unsupported protocol: " + protocol); + logger.logDebug("Cannot wrap unsupported protocol: " + protocol); return parentConnection; } } diff --git a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/logging/InternalStaticEmbraceLogger.kt b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/logging/InternalStaticEmbraceLogger.kt index 63c546b83f..4f9cd3b2b1 100644 --- a/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/logging/InternalStaticEmbraceLogger.kt +++ b/embrace-android-sdk/src/main/java/io/embrace/android/embracesdk/logging/InternalStaticEmbraceLogger.kt @@ -1,66 +1,9 @@ package io.embrace.android.embracesdk.logging -// Suppressing "Nothing to inline". These functions are used all around the codebase, pretty often, so we want them to -// perform as fast as possible. -@Suppress("NOTHING_TO_INLINE") -internal class InternalStaticEmbraceLogger private constructor() { - - companion object : InternalEmbraceLogger.LoggerAction { - - @JvmField - val logger = InternalEmbraceLogger() - - @JvmStatic - @JvmOverloads - inline fun logDebug(msg: String, throwable: Throwable? = null) { - log(msg, InternalEmbraceLogger.Severity.DEBUG, throwable, true) - } - - @JvmStatic - inline fun logInfo(msg: String) { - log(msg, InternalEmbraceLogger.Severity.INFO, null, true) - } - - @JvmStatic - @JvmOverloads - inline fun logWarning(msg: String, throwable: Throwable? = null) { - log(msg, InternalEmbraceLogger.Severity.WARNING, throwable, true) - } - - @JvmStatic - @JvmOverloads - inline fun logError(msg: String, throwable: Throwable? = null, logStacktrace: Boolean = false) { - log(msg, InternalEmbraceLogger.Severity.ERROR, throwable, logStacktrace) - } - - // Log with INFO severity that always contains a throwable as an internal exception to be sent to Grafana - inline fun logInfoWithException(msg: String, throwable: Throwable? = null, logStacktrace: Boolean = false) { - log(msg, InternalEmbraceLogger.Severity.INFO, throwable ?: InternalErrorLogger.NotAnException(msg), logStacktrace) - } - - // Log with WARNING severity that always contains a throwable as an internal exception to be sent to Grafana - inline fun logWarningWithException(msg: String, throwable: Throwable? = null, logStacktrace: Boolean = false) { - log(msg, InternalEmbraceLogger.Severity.WARNING, throwable ?: InternalErrorLogger.NotAnException(msg), logStacktrace) - } - - /** - * Logs a message. - * - * @param msg the message to log. - * @param severity how severe the log is. If it's lower than the threshold, the message will not be logged. - * @param throwable exception, if any. - * @param logStacktrace should add the throwable to the logging - */ - - @JvmStatic - override fun log( - msg: String, - severity: InternalEmbraceLogger.Severity, - throwable: Throwable?, - logStacktrace: Boolean - ) = logger.log(msg, severity, throwable, logStacktrace) - - @JvmStatic - fun setThreshold(severity: InternalEmbraceLogger.Severity) = logger.setThreshold(severity) - } +/** + * A version of the logger used when the SDK instance is not readily available + */ +internal object InternalStaticEmbraceLogger { + @JvmField + val logger = InternalEmbraceLogger() }