Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QA] Make logging faster on startup #3793

Merged
merged 4 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Vendor `java.util.Random` and replace `java.security.SecureRandom` usages ([#3783](https://github.com/getsentry/sentry-java/pull/3783))
- Fix potential ANRs due to NDK scope sync ([#3754](https://github.com/getsentry/sentry-java/pull/3754))
- Fix potential ANRs due to NDK System.loadLibrary calls ([#3670](https://github.com/getsentry/sentry-java/pull/3670))
- Fix slow `Log` calls on app startup ([#3793](https://github.com/getsentry/sentry-java/pull/3793))

## 7.15.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ public void log(
final @NotNull SentryLevel level,
final @NotNull String message,
final @Nullable Object... args) {
Log.println(toLogcatLevel(level), tag, String.format(message, args));
if (args == null || args.length == 0) {
Log.println(toLogcatLevel(level), tag, message);
} else {
Log.println(toLogcatLevel(level), tag, String.format(message, args));
}
}

@SuppressWarnings("AnnotateFormatMethod")
Expand All @@ -36,7 +40,11 @@ public void log(
final @Nullable Throwable throwable,
final @NotNull String message,
final @Nullable Object... args) {
log(level, String.format(message, args), throwable);
if (args == null || args.length == 0) {
log(level, message, throwable);
} else {
log(level, String.format(message, args), throwable);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ private static boolean readBool(
final @NotNull String key,
final boolean defaultValue) {
final boolean value = metadata.getBoolean(key, defaultValue);
logger.log(SentryLevel.DEBUG, "%s read: %s", key, value);
logger.log(SentryLevel.DEBUG, key + " read: " + value);
return value;
}

Expand All @@ -450,10 +450,10 @@ private static boolean readBool(
if (metadata.getSerializable(key) != null) {
final boolean nonNullDefault = defaultValue == null ? false : true;
final boolean bool = metadata.getBoolean(key, nonNullDefault);
logger.log(SentryLevel.DEBUG, "%s read: %s", key, bool);
logger.log(SentryLevel.DEBUG, key + " read: " + bool);
return bool;
} else {
logger.log(SentryLevel.DEBUG, "%s used default %s", key, defaultValue);
logger.log(SentryLevel.DEBUG, key + " used default " + defaultValue);
return defaultValue;
}
}
Expand All @@ -464,7 +464,7 @@ private static boolean readBool(
final @NotNull String key,
final @Nullable String defaultValue) {
final String value = metadata.getString(key, defaultValue);
logger.log(SentryLevel.DEBUG, "%s read: %s", key, value);
logger.log(SentryLevel.DEBUG, key + " read: " + value);
return value;
}

Expand All @@ -474,14 +474,14 @@ private static boolean readBool(
final @NotNull String key,
final @NotNull String defaultValue) {
final String value = metadata.getString(key, defaultValue);
logger.log(SentryLevel.DEBUG, "%s read: %s", key, value);
logger.log(SentryLevel.DEBUG, key + " read: " + value);
return value;
}

private static @Nullable List<String> readList(
final @NotNull Bundle metadata, final @NotNull ILogger logger, final @NotNull String key) {
final String value = metadata.getString(key);
logger.log(SentryLevel.DEBUG, "%s read: %s", key, value);
logger.log(SentryLevel.DEBUG, key + " read: " + value);
if (value != null) {
return Arrays.asList(value.split(",", -1));
} else {
Expand All @@ -493,7 +493,7 @@ private static boolean readBool(
final @NotNull Bundle metadata, final @NotNull ILogger logger, final @NotNull String key) {
// manifest meta-data only reads float
final Double value = ((Float) metadata.getFloat(key, -1)).doubleValue();
logger.log(SentryLevel.DEBUG, "%s read: %s", key, value);
logger.log(SentryLevel.DEBUG, key + " read: " + value);
return value;
}

Expand All @@ -504,7 +504,7 @@ private static long readLong(
final long defaultValue) {
// manifest meta-data only reads int if the value is not big enough
final long value = metadata.getInt(key, (int) defaultValue);
logger.log(SentryLevel.DEBUG, "%s read: %s", key, value);
logger.log(SentryLevel.DEBUG, key + " read: " + value);
return value;
}

Expand All @@ -524,7 +524,6 @@ static boolean isAutoInit(final @NotNull Context context, final @NotNull ILogger
if (metadata != null) {
autoInit = readBool(metadata, logger, AUTO_INIT, true);
}
logger.log(SentryLevel.INFO, "Retrieving auto-init from AndroidManifest.xml");
} catch (Throwable e) {
logger.log(SentryLevel.ERROR, "Failed to read auto-init from android manifest metadata.", e);
}
Expand Down
Loading