Skip to content

Commit

Permalink
Add ctor to JUL for disabling external config
Browse files Browse the repository at this point in the history
  • Loading branch information
adinauer committed Feb 25, 2025
1 parent e5e95de commit c8c5eb1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions sentry-jul/api/sentry-jul.api
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class io/sentry/jul/SentryHandler : java/util/logging/Handler {
public static final field THREAD_ID Ljava/lang/String;
public fun <init> ()V
public fun <init> (Lio/sentry/SentryOptions;)V
public fun <init> (Lio/sentry/SentryOptions;Z)V
public fun close ()V
public fun flush ()V
public fun getMinimumBreadcrumbLevel ()Ljava/util/logging/Level;
Expand Down
23 changes: 19 additions & 4 deletions sentry-jul/src/main/java/io/sentry/jul/SentryHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class SentryHandler extends Handler {

/** Creates an instance of SentryHandler. */
public SentryHandler() {
this(new SentryOptions(), true);
this(new SentryOptions());
}

/**
Expand All @@ -60,17 +60,32 @@ public SentryHandler() {
* @param options the SentryOptions
*/
public SentryHandler(final @NotNull SentryOptions options) {
this(options, true);
this(options, true, true);
}

/**
* Creates an instance of SentryHandler.
*
* @param options the SentryOptions
* @param enableExternalConfiguration whether external options like sentry.properties and ENV vars
* should be parsed
*/
public SentryHandler(
final @NotNull SentryOptions options, final boolean enableExternalConfiguration) {
this(options, true, enableExternalConfiguration);
}

/** Creates an instance of SentryHandler. */
@TestOnly
SentryHandler(final @NotNull SentryOptions options, final boolean configureFromLogManager) {
SentryHandler(
final @NotNull SentryOptions options,
final boolean configureFromLogManager,
final boolean enableExternalConfiguration) {
setFilter(new DropSentryFilter());
if (configureFromLogManager) {
retrieveProperties();
}
options.setEnableExternalConfiguration(true);
options.setEnableExternalConfiguration(enableExternalConfiguration);
options.setInitPriority(InitPriority.LOWEST);
options.setSdkVersion(createSdkVersion(options));
Sentry.init(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SentryHandlerTest {
options.setTransportFactory { _, _ -> transport }
contextTags?.forEach { options.addContextTag(it) }
logger = Logger.getLogger("jul.SentryHandlerTest")
handler = SentryHandler(options, configureWithLogManager)
handler = SentryHandler(options, configureWithLogManager, true)
handler.setMinimumBreadcrumbLevel(minimumBreadcrumbLevel)
handler.setMinimumEventLevel(minimumEventLevel)
handler.level = Level.ALL
Expand Down

0 comments on commit c8c5eb1

Please sign in to comment.