From f545e8ddfe2807cd6c55d3cccbdfcf7f443280e2 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Thu, 19 May 2022 12:06:00 +0200 Subject: [PATCH 1/2] Improve jul sample for easier debugging inside IDE --- buildSrc/src/main/java/Config.kt | 1 + sentry-samples/sentry-samples-jul/build.gradle.kts | 3 +-- .../src/main/java/io/sentry/samples/jul/Main.java | 6 +++++- .../src/main/resources/logging.properties | 6 +++--- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/buildSrc/src/main/java/Config.kt b/buildSrc/src/main/java/Config.kt index 27bb77b26c..5d910669b6 100644 --- a/buildSrc/src/main/java/Config.kt +++ b/buildSrc/src/main/java/Config.kt @@ -52,6 +52,7 @@ object Config { val androidxRecylerView = "androidx.recyclerview:recyclerview:1.2.1" val slf4jApi = "org.slf4j:slf4j-api:1.7.30" + val slf4jJdk14 = "org.slf4j:slf4j-jdk14:1.7.30" val logbackVersion = "1.2.9" val logbackClassic = "ch.qos.logback:logback-classic:$logbackVersion" diff --git a/sentry-samples/sentry-samples-jul/build.gradle.kts b/sentry-samples/sentry-samples-jul/build.gradle.kts index dcf75a4620..aef8c4b7f8 100644 --- a/sentry-samples/sentry-samples-jul/build.gradle.kts +++ b/sentry-samples/sentry-samples-jul/build.gradle.kts @@ -8,7 +8,6 @@ plugins { application { mainClass.set("io.sentry.samples.jul.Main") - applicationDefaultJvmArgs = mutableListOf("-Djava.util.logging.config.file=${project.projectDir}/src/main/resources/logging.properties") } configure { @@ -18,5 +17,5 @@ configure { dependencies { implementation(projects.sentryJul) - implementation(Config.Libs.logbackClassic) + implementation(Config.Libs.slf4jJdk14) } diff --git a/sentry-samples/sentry-samples-jul/src/main/java/io/sentry/samples/jul/Main.java b/sentry-samples/sentry-samples-jul/src/main/java/io/sentry/samples/jul/Main.java index 3181703411..aeadcfeec7 100644 --- a/sentry-samples/sentry-samples-jul/src/main/java/io/sentry/samples/jul/Main.java +++ b/sentry-samples/sentry-samples-jul/src/main/java/io/sentry/samples/jul/Main.java @@ -2,6 +2,7 @@ import java.util.UUID; import java.util.logging.Level; +import java.util.logging.LogManager; import java.util.logging.Logger; import org.slf4j.MDC; @@ -9,11 +10,14 @@ public class Main { private static final Logger LOGGER = Logger.getLogger(Main.class.getName()); - public static void main(String[] args) { + public static void main(String[] args) throws Exception { + LogManager.getLogManager() + .readConfiguration(Main.class.getClassLoader().getResourceAsStream("logging.properties")); LOGGER.config("Hello Sentry!"); // MDC parameters are converted to Sentry Event tags MDC.put("userId", UUID.randomUUID().toString()); + MDC.put("requestId", UUID.randomUUID().toString()); // logging arguments are converted to Sentry Event parameters LOGGER.log(Level.INFO, "User has made a purchase of product: %d", 445); diff --git a/sentry-samples/sentry-samples-jul/src/main/resources/logging.properties b/sentry-samples/sentry-samples-jul/src/main/resources/logging.properties index 5eb5771d2e..52f5cdef33 100644 --- a/sentry-samples/sentry-samples-jul/src/main/resources/logging.properties +++ b/sentry-samples/sentry-samples-jul/src/main/resources/logging.properties @@ -1,6 +1,6 @@ -io.sentry.jul.SentryHandler.minimumEventLevel=INFO +io.sentry.jul.SentryHandler.minimumEventLevel=DEBUG io.sentry.jul.SentryHandler.minimumBreadcrumbLevel=CONFIG io.sentry.jul.SentryHandler.printfStyle=true io.sentry.jul.SentryHandler.level=CONFIG -io.sentry.samples.jul.Main.handlers=io.sentry.jul.SentryHandler -io.sentry.samples.jul.Main.level=CONFIG +handlers=io.sentry.jul.SentryHandler +level=CONFIG From 80f80ef0696632761f760668efa32ccdcec54f7b Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Thu, 19 May 2022 14:04:21 +0200 Subject: [PATCH 2/2] Add comment on how to specify logging.properties file instead of in the code --- .../src/main/java/io/sentry/samples/jul/Main.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sentry-samples/sentry-samples-jul/src/main/java/io/sentry/samples/jul/Main.java b/sentry-samples/sentry-samples-jul/src/main/java/io/sentry/samples/jul/Main.java index aeadcfeec7..86030003f6 100644 --- a/sentry-samples/sentry-samples-jul/src/main/java/io/sentry/samples/jul/Main.java +++ b/sentry-samples/sentry-samples-jul/src/main/java/io/sentry/samples/jul/Main.java @@ -11,6 +11,9 @@ public class Main { private static final Logger LOGGER = Logger.getLogger(Main.class.getName()); public static void main(String[] args) throws Exception { + // instead of the following line you can also pass + // -Djava.util.logging.config.file=.../logging.properties to the + // java command LogManager.getLogManager() .readConfiguration(Main.class.getClassLoader().getResourceAsStream("logging.properties")); LOGGER.config("Hello Sentry!");