Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,23 @@ static void applyMetadata(
}
}

if (metadata.containsKey(ENABLE_LOGS)) {
final boolean enableLogs = readBool(metadata, logger, ENABLE_LOGS, false);
if (enableLogs) {
logger.log(
SentryLevel.WARNING,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who reads logs these days? I get the feeling nobody will see it.

"The Android manifest option 'io.sentry.logs.enabled' is no longer supported. "
+ "Manual Sentry.logger() calls no longer require it, and automatic logging "
+ "integrations now require their own opt-ins.");
} else {
logger.log(
SentryLevel.WARNING,
"The Android manifest option 'io.sentry.logs.enabled' no longer disables manual "
+ "Sentry.logger() calls. Automatic logging integrations remain disabled "
+ "unless enabled through their own opt-ins.");
}
}

options.setEnableTimberLogs(
readBool(metadata, logger, ENABLE_TIMBER_LOGS, options.isEnableTimberLogs()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import org.mockito.kotlin.verify
class ManifestMetadataReaderTest {
private class Fixture {
val logger = mock<ILogger>()
val options = SentryAndroidOptions().apply { setLogger(logger) }
val options = SentryAndroidOptions().apply { setLogger(this@Fixture.logger) }
val buildInfoProvider = mock<BuildInfoProvider>()

fun getContext(metaData: Bundle = Bundle()): Context =
Expand Down Expand Up @@ -1943,6 +1943,64 @@ class ManifestMetadataReaderTest {
assertTrue(fixture.options.inAppExcludes.isEmpty())
}

@Test
fun `applyMetadata does not warn when legacy logs enabled metadata is absent`() {
fixture.options.isDebug = true
val context = fixture.getContext()

ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)

verify(fixture.logger, never()).log(eq(SentryLevel.WARNING), any<String>())
}

@Test
fun `applyMetadata warns when legacy logs enabled metadata is true`() {
val bundle =
bundleOf(
ManifestMetadataReader.DEBUG to true,
ManifestMetadataReader.ENABLE_LOGS to true,
)
val context = fixture.getContext(metaData = bundle)

ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)

verify(fixture.logger)
.log(
SentryLevel.WARNING,
"The Android manifest option 'io.sentry.logs.enabled' is no longer supported. " +
"Manual Sentry.logger() calls no longer require it, and automatic logging " +
"integrations now require their own opt-ins.",
*emptyArray(),
)
assertThat(fixture.options.isEnableTimberLogs).isFalse()
assertThat(fixture.options.isEnableLogcatLogs).isFalse()
}

@Test
fun `applyMetadata warns when legacy logs enabled metadata is false`() {
fixture.options.isEnableTimberLogs = true
fixture.options.isEnableLogcatLogs = true
val bundle =
bundleOf(
ManifestMetadataReader.DEBUG to true,
ManifestMetadataReader.ENABLE_LOGS to false,
)
val context = fixture.getContext(metaData = bundle)

ManifestMetadataReader.applyMetadata(context, fixture.options, fixture.buildInfoProvider)

verify(fixture.logger)
.log(
SentryLevel.WARNING,
"The Android manifest option 'io.sentry.logs.enabled' no longer disables manual " +
"Sentry.logger() calls. Automatic logging integrations remain disabled unless " +
"enabled through their own opt-ins.",
*emptyArray(),
)
assertThat(fixture.options.isEnableTimberLogs).isTrue()
assertThat(fixture.options.isEnableLogcatLogs).isTrue()
}

@Test
fun `applyMetadata keeps Timber logs disabled if not found`() {
val context = fixture.getContext()
Expand Down
Loading