Skip to content

Commit

Permalink
Remove extra logging
Browse files Browse the repository at this point in the history
  • Loading branch information
bidetofevil committed May 16, 2024
1 parent 248a719 commit d5f5413
Show file tree
Hide file tree
Showing 9 changed files with 5 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ private static void handleRemoteMessage(@NonNull RemoteMessage message) {
}

private static void logError(@NonNull String message, @Nullable Exception e) {
Embrace.getInstance().getInternalInterface().logError(message, null, null, false);
if (e != null) {
Embrace.getInstance().getInternalInterface().logInternalError(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ private Builder() {
*/
@SuppressWarnings("MethodNameCheck")
public static void _preBuild(okhttp3.OkHttpClient.Builder thiz) {
logInfo("Embrace OkHTTP Wrapper; onPrebuild");
addEmbraceInterceptors(thiz);
}

@SuppressWarnings("MethodNameCheck")
public static void _constructorOnPostBody(okhttp3.OkHttpClient.Builder thiz) {
logInfo("Embrace OkHTTP Wrapper; onPostBody");
addEmbraceInterceptors(thiz);
}

Expand All @@ -51,15 +49,14 @@ public static void _constructorOnPostBody(okhttp3.OkHttpClient.Builder thiz) {
*/
private static void addEmbraceInterceptors(okhttp3.OkHttpClient.Builder thiz) {
try {
logInfo("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.
logError("Altered OkHttpClient implementation, could not add OkHttp interceptor. ", exception);
logInternalError("Altered OkHttpClient implementation, could not add OkHttp interceptor. ", exception);
} catch (Exception exception) {
logError("Could not add OkHttp interceptor. ", exception);
logInternalError("Could not add OkHttp interceptor. ", exception);
}
}

Expand All @@ -73,10 +70,6 @@ private static void addInterceptor(List<Interceptor> interceptors,
Interceptor interceptor) {
if (interceptors != null && !containsInstance(interceptors, interceptor.getClass())) {
interceptors.add(0, interceptor);
} else {
logInfo(
"Not adding interceptor [" + interceptor.getClass().getSimpleName() + "]"
);
}
}

Expand All @@ -92,21 +85,13 @@ private static <T> boolean containsInstance(List<T> elementsList,
Class<? extends T> clazz) {
for (T classInstance : elementsList) {
if (clazz.isInstance(classInstance)) {
logInfo(
"[" + clazz.getSimpleName() + "] already present in list"
);
return true;
}
}
return false;
}

private static void logInfo(String message) {
Embrace.getInstance().getInternalInterface().logInfo(message, null);
}

private static void logError(String message, Throwable throwable) {
Embrace.getInstance().getInternalInterface().logError(message, null, null, false);
private static void logInternalError(String message, Throwable throwable) {
Embrace.getInstance().getInternalInterface().logInternalError(throwable);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package io.embrace.android.embracesdk;

import kotlin.Pair;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import io.embrace.android.embracesdk.annotation.InternalApi;
import io.embrace.android.embracesdk.payload.TapBreadcrumb.TapBreadcrumbType;
import kotlin.Pair;

/**
* @hide
Expand Down Expand Up @@ -44,7 +43,6 @@ static void logOnClickEvent(android.view.View view, TapBreadcrumbType breadcrumb
}

private static void logError(@NonNull String message, @Nullable Throwable throwable) {
Embrace.getInstance().getInternalInterface().logError(message, null, null, false);
if (throwable != null) {
Embrace.getInstance().getInternalInterface().logInternalError(throwable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ private WebViewChromeClientSwazzledHooks() {

@SuppressWarnings("MethodNameCheck")
public static void _preOnConsoleMessage(@NonNull ConsoleMessage consoleMessage) {
Embrace.getInstance().getInternalInterface().logInfo("webview _preOnConsoleMessage", null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import androidx.annotation.Nullable;

import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.regex.Pattern;

import io.embrace.android.embracesdk.Embrace;
import io.embrace.android.embracesdk.annotation.InternalApi;

@InternalApi
Expand Down Expand Up @@ -54,38 +52,24 @@ public static String getURLString(@NonNull HttpPathOverrideRequest request, @Nul

private static Boolean validatePathOverride(String path) {
if (path == null) {
logError("URL relative path cannot be null");
return false;
}
if (path.isEmpty()) {
logError("Relative path must have non-zero length");
return false;
}
if (path.length() > RELATIVE_PATH_MAX_LENGTH) {
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)) {
logError("Relative path must not contain unicode " +
"characters. Relative path " + path + " will be ignored.");
return false;
}
if (!path.startsWith("/")) {
logError("Relative path must start with a /");
return false;
}
if (!RELATIVE_PATH_PATTERN.matcher(path).matches()) {
logError("Relative path contains invalid chars. " +
"Relative path " + path + " will be ignored.");
return false;
}

return true;
}

private static void logError(@NonNull String message) {
Embrace.getInstance().getInternalInterface().logError(message, null, null, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import java.net.MalformedURLException;
import java.net.URL;

import io.embrace.android.embracesdk.Embrace;

class EmbraceHttpUrlConnectionOverride implements HttpPathOverrideRequest {

private final HttpURLConnection connection;
Expand All @@ -30,8 +28,6 @@ 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) {
Embrace.getInstance().getInternalInterface().logError(
"Failed to override path of " + connection.getURL() + " with " + pathOverride, null, null, false);
return connection.getURL().toString();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,7 @@ private void identifyTraceId() {
try {
traceId = getRequestProperty(embrace.getTraceIdHeader());
} catch (Exception e) {
Embrace.getInstance().getInternalInterface().logWarning(
"Failed to retrieve actual trace id header. Current: " + traceId, null, null);
// don't do anything
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ static URLStreamHandler newUrlStreamHandler(String className) {
}

private static void logError(@NonNull String message, @Nullable Throwable throwable) {
Embrace.getInstance().getInternalInterface().logError(message, null, null, false);
if (throwable != null) {
Embrace.getInstance().getInternalInterface().logInternalError(throwable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,8 @@ 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
Embrace.getInstance().getInternalInterface().logInfo("Registering EmbraceUrlStreamHandlerFactory.", null);
URL.setURLStreamHandlerFactory(new EmbraceUrlStreamHandlerFactory());
} else {
Embrace.getInstance().getInternalInterface().logInfo("Existing URLStreamHandlerFactory detected " +
"(" + existingFactory.getClass().getName() + "). Wrapping with Embrace factory " +
"to enable network traffic interception.", null);
WrappingFactory wrappingFactory = new WrappingFactory((URLStreamHandlerFactory) existingFactory, enableRequestSizeCapture);
clearFactory();
URL.setURLStreamHandlerFactory(wrappingFactory);
Expand Down Expand Up @@ -105,7 +101,6 @@ private static void clearFactory() {
}

static void logError(@NonNull String message, @Nullable Throwable throwable) {
Embrace.getInstance().getInternalInterface().logError(message, null, null, false);
if (throwable != null) {
Embrace.getInstance().getInternalInterface().logInternalError(throwable);
}
Expand Down

0 comments on commit d5f5413

Please sign in to comment.